-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Form] Document "class constraints" for data class-less forms #18969
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
Comments
Interesting, I think this could be a great addition to the docs. Open for a PR against cc @xabbuh |
I think it would be a good idea to expand the examples around this a bit. |
Here's the 2nd example brought into more modern PHP. function configureOptions(OptionsResolver $resolver): void {
$collectionConstraint = new Collection([
'CardNumber' => [
new CardScheme([
'schemes' => ['VISA', 'MASTERCARD', 'DISCOVER'],
'message' => 'The credit card number you entered is invalid.'
])
],
'SecurityCode' => [
new Length(exactly: 3)
]
]);
$resolver->setDefaults([
'data_class' => null,
'constraints' => $collectionConstraint
]);
} Should I create a complete example formtype or two for this? |
Friendly ping @alexandre-daubois if you want to help 🤓 |
I gave it a try! |
javiereguiluz
added a commit
that referenced
this issue
Jan 9, 2025
…int to validate array-like data (xabbuh) This PR was merged into the 6.4 branch. Discussion ---------- [Form] wrap multiple constraints in a Collection constraint to validate array-like data fixes symfony/symfony#59332, replaces #20487 see also #18969 (comment) Commits ------- 6e71ed0 wrap multiple constraints in a Collection constraint to validate array-like data
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Symfony supports using a Form without using a Data Class.
In that page it mentions how to validate individual fields using a constraint, however it's also possible to add constraints to the root form:
(src)
configureOptions
->(src)
(Note: Callback constraints are also allowed and have access to the whole form)
The text was updated successfully, but these errors were encountered: