Skip to content
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

implement a readonly and a disabled validator #797

Merged

Conversation

azmeuk
Copy link
Member

@azmeuk azmeuk commented Jul 22, 2023

Fixes #792

This adds two validators readonly and disabled.

The validators adds the corresponding flags on the widgets on which this is authorized, according to MDN.

The readonly validator raises a ValidationError if the formdata is different than the object data for a given form. The disabled validator raises a ValidationError if the formdata is different than None.

Readonly fields are sent by the browser, and disabled ones are not. Either ways those validators prevents the user from cheating and submitting different values that the ones they have been presented.

If someone wants a readonly field but does not want to enforce the immutability, they still can use render_kw.

@azmeuk azmeuk added the enhancement New feature, or existing feature improvement label Jul 22, 2023
@azmeuk azmeuk marked this pull request as draft July 25, 2023 15:42
@azmeuk
Copy link
Member Author

azmeuk commented Jul 25, 2023

I should look how this behaves for FieldList and FormField.

@azmeuk azmeuk force-pushed the issue-792-readonly-disabled-fields branch from 6aa6fd9 to 40e39f3 Compare July 27, 2023 16:07
@azmeuk azmeuk marked this pull request as ready for review July 27, 2023 16:08
@azmeuk azmeuk force-pushed the issue-792-readonly-disabled-fields branch from 40e39f3 to df64872 Compare July 28, 2023 19:28
Comment on lines 703 to 704
Validation fails if the form data is different than the
field object data, or if unset, from the field default data.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not correct

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Now this is Validation fails if the form data has any value.

@azmeuk azmeuk force-pushed the issue-792-readonly-disabled-fields branch from df64872 to 2e8d970 Compare September 30, 2023 17:34
@azmeuk azmeuk force-pushed the issue-792-readonly-disabled-fields branch from 2e8d970 to 5ae63d8 Compare October 5, 2023 09:39
@azmeuk azmeuk merged commit 5e0f444 into pallets-eco:master Oct 5, 2023
7 checks passed
@azmeuk azmeuk deleted the issue-792-readonly-disabled-fields branch October 5, 2023 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, or existing feature improvement
Development

Successfully merging this pull request may close these issues.

HTML readonly attribute support
2 participants