Skip to content

Conversation

mickaelandrieu
Copy link
Contributor

Hello!

regarding the way I validate my forms, I've always found that storing validation rules into my entities is a better idea than using the constraints inside my form types.

When I need a really specific control on my form validation, I inject validation groups: do you think it can be viewed as a best practice?

public $title;
}

This make them reusables and independents from the validation rules.
Copy link
Member

Choose a reason for hiding this comment

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

independent

----------

Define your validation constraints outside of the forms, for instance directly on the object
class used as data mapper::
Copy link
Member

Choose a reason for hiding this comment

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

Maybe reword it a bit like this:

Do not define your validation constraint with the constraints option. Configure them on the object the form is mapped to instead:

@xabbuh
Copy link
Member

xabbuh commented Sep 12, 2018

👍 I agree

@mickaelandrieu
Copy link
Contributor Author

Hi @xabbuh, thanks for the review :)

Thinking about it, is it a good place to add a note about validation groups?

Something like:

If you need to apply multiple sets of rules using the same form type, use validation groups.

With a minimal example attached to this note: WDYT?

@xabbuh
Copy link
Member

xabbuh commented Sep 12, 2018

I think it would probably be better to put it the other way around:

If your form requires only a subset of all the configured validation constraints, [...]

And then just link this paragraph to the article about validation groups.

@javiereguiluz
Copy link
Member

@mickaelandrieu I liked both your original proposal and the reword suggestions made by @xabbuh so I reworded this accordingly. What do you think? Thanks!

@mickaelandrieu
Copy link
Contributor Author

mickaelandrieu commented Sep 13, 2018

@javiereguiluz you have improved my proposal as always!

Thank you 👍

Edit: so we don't add a note about validation groups?

Validation
----------

The `constraints`_ option allows you to attach `validation constraints`_ to any
Copy link
Member

Choose a reason for hiding this comment

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

we should use the doc or ref role here instead

@javiereguiluz
Copy link
Member

I've merged this "as is" and I'll fix the internal links in a separate PR. Thanks Mickaël!

javiereguiluz added a commit that referenced this pull request Sep 19, 2018
…ieu, javiereguiluz) This PR was submitted for the 4.1 branch but it was merged into the 2.8 branch instead (closes #10331). Discussion ---------- (Proposal) Added a note on forms validation Hello! regarding the way I validate my forms, I've always found that storing validation rules into my entities is a better idea than using the constraints inside my form types. When I need a really specific control on my form validation, I inject validation groups: do you think it can be viewed as a best practice? Commits ------- 68a7931 Reword 21c4c9f Added a note on forms validation
javiereguiluz added a commit that referenced this pull request Sep 19, 2018
This PR was merged into the 2.8 branch. Discussion ---------- Use cross references for internal links This PR updates the internal links of #10331. Commits ------- 8e41b98 Use cross references for internal links
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants