elo80ka / django-dynamic-formset

A jQuery plugin that allows you dynamically add new forms to a rendered django formset.
677 stars 311 forks source link

Clicking on add row in update mode displays foreign keys even if label is none. #193

Closed dunkinman closed 3 years ago

dunkinman commented 3 years ago

This code is amazing! I recently stumbled across an issue wherein if the formset is in an update mode and extra is set to 0 and a formset row has a foreign key, if you click on Add row, it duplicates the row and a foreign key selection is show even if empty label is supposed to be blank. Is this a bug? I read through some of the source code and it says that this works better if extra is set to 1 or higher but I'd rather not have an extra empty row in this view. I look through the source code and it's a bit over my head as to why the foreign key is displayed in this scenario when everything else is blank as appears to be intended. Is anyone able to suggest a fix to this scenario? Thanks in advance!

dunkinman commented 3 years ago

I have since determined it was not a bug, just additional code that needed to be written. I solved it by adding the following two lines of code... if (elem.is('select')) { elem.append(''); } For some reason the text isn't displaying in my answer. Many sure to include....option style="display:none" selected value="" in the append...surrounded by option and /option