Skip to content

Form fields' custom options should be validated when constructing the field #294

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

Open
m4tx opened this issue Apr 25, 2025 · 1 comment · May be fixed by #304
Open

Form fields' custom options should be validated when constructing the field #294

m4tx opened this issue Apr 25, 2025 · 1 comment · May be fixed by #304
Labels
enhancement New feature or request

Comments

@m4tx
Copy link
Member

m4tx commented Apr 25, 2025

In case we have form fields that have custom options that might conflict with each other (for instance, "minimum length" and "maximum length", where min > max), we should be able to generate an error when constructing a field, rather than in clean_value, for instance.

Technically, this is now possible by overriding FormField::with_options and just panicking there. Right now, we implement this trait with a macro (impl_form_field), so there are multiple options to solve the problem:

  • Change the macro so that some additional code can be added to the FormField::with_options implementation
  • Change the FormField::CustomOptions type to enforce validation before constructing an instance of CustomOptions somehow (this approach is slightly more complicated, because this would require some changes in the derive macro implementations, but is arguably more "correct")
  • Come up with something else?

Context: #286 (comment)

@ElijahAhianyo
Copy link
Contributor

ElijahAhianyo commented Apr 29, 2025

@m4tx I moved the validation to the Field creation by introducing a ValidateOptions trait, which should be called before the field is created here #304 . What are your initial thoughts about this approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants