fixed bug which caused bound forms to lose selected option#89
Open
io2 wants to merge 6 commits intodjango-crispy-forms:mainfrom
Open
fixed bug which caused bound forms to lose selected option#89io2 wants to merge 6 commits intodjango-crispy-forms:mainfrom
io2 wants to merge 6 commits intodjango-crispy-forms:mainfrom
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
Member
|
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. Secondly is that this can be improved using the new |
Contributor
Author
|
@smithdc1 I'll take a look sometime and push an update. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
in django
forms.ModelFormtypes, theselect > optionvalue attribute is usually set to the primary key of the model object (typically an integer)This commit converts
field.valueto string to ensure theifcondition for addingselectedto the<option>html is satisfied.