-
Notifications
You must be signed in to change notification settings - Fork 162
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
read-only fields on validation error #260
Comments
I am having exactly the same problem. Hidden field is another solution, but from time to time we may need the field to be displayed. So this is a bit embarrasiing. The other approach I used is to actually write a function which converts the post item list to appstruct when validation fails, so that we can still keep the data. |
I have run into this problem and ended up creating a custom readonly widget (similar to what @J20S suggested). My reasoning for this was that it would still allow me to present a "display" of the information without disclosing or polluting the HTML with hidden form elements when they were not needed. However, when a form element needed to be fixed/readonly, but still re-populate if the form wasn't validate then to render a hidden input along with the text output of the value. |
With the last version of deform, with Bootstrap 3+ I can add HTML attributes to the field: |
@magoarcano your work-around is what the library should likely be doing rather than the current which just outputs the data in HTML. |
@bertjwregeer You're right. In the way I proposed it works, there is no validation errors, the data doesn't disappear on Posting. But on the other hand user could hack the form and POST the data changing that readonly value. So validator code should be fixed then. |
The UI for the workaround is fine for TextInputWidgets, but it is horrible for selects, radios, and checkboxes. The user can click these elements and their changes may be saved. I think a more UI friendly method is to render the values as just plain text and insert a hidden input with the value of the form element. |
Upon further thought, we can set the checked/selected values as readonly, and the unchecked/unselected values as disabled, either through HTML or JavaScript. See https://stackoverflow.com/questions/1953017/why-cant-radio-buttons-be-readonly |
This issue will need documentation that distinguishes between |
To display the un/selected values for checkboxes, use |
Single selects are similar to radios. Multiple selects however are problematic. I don't yet have a solution for plain old multiple selects because I can deselect selected options, submit the form, and the values are updated. For Select2 multiple selects, we can lock selections or https://stackoverflow.com/a/24109346/2214933. |
Bad news. Plain old multiple selects do not allow locking of selected values. I might be able to do something with JavaScript, not sure yet. Select2 had the locked feature in 3.5.x, but was dropped in 4.0, and it looks like it will not get this feature back any time soon. We might want to switch to another select widget.
|
I think I will add selectize.js and not attempt to write custom JavaScript that locks the selected values in a multiple select input. I never use the default select when I use multiple values, preferring to use select2. selectize.js looks better all around, and just 10 days ago new maintainers jumped on board. |
In Deform 2.0.15, I plan to deprecate To replace it, I will add a new widget If anyone has any objection to this plan, please speak now! |
Fixed and released in v.2.0.15. |
Read-only fields are only displayed and aren't included on form submission. If a person submits a form with read-only elements those elements aren't included. If the form doesn't validate, then,
deform.exception.ValidationFailure.render()
doesn't contain the previous values for those read-only elements and then leaves it blank.What's the typical way of handling this issue? It seems like it's not dealt with at http://deform2demo.repoze.org/readonly_argument/ (just try submitting the page there and all the values disappear)
Should we be including hidden fields with read-only elements purely for display usage?
The text was updated successfully, but these errors were encountered: