-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed bug which caused bound forms to lose selected option #89
base: main
Are you sure you want to change the base?
Conversation
When using any of the `formset_factory`s to generate multiple forms, the select fields lose their values if the form is returned with an error. This happens because the template renders `field.name` instead of `field.html_name`. `field.name` is the same for all forms, `field.html_name` is unique for each form instance
in forms.ModelForm types, the `select > option` value attribute is usually set to the primary key of the model object (usually an int) This commit converts `field.value` to string to ensure the `if` condition for adding selected to the <option> is met. Added tests to better demonstrate the issue
Hi @io2 Sorry for taking some time to get to this. There's a few things going on with this at the moment. The first is that we should probably mirror the logic from checkboxes and radios. There are a few other edge cases we should look to capture. See this line here. crispy-tailwind/crispy_tailwind/templates/tailwind/layout/checkboxselectmultiple.html Line 8 in 3ad4c94
Secondly is that this can be improved using the new |
@smithdc1 I'll take a look sometime and push an update. |
in django
forms.ModelForm
types, theselect > option
value attribute is usually set to the primary key of the model object (typically an integer)This commit converts
field.value
to string to ensure theif
condition for addingselected
to the<option>
html is satisfied.