symfony - Get entity assert property in form view (or in form builder) to use with JS -
i'm trying access assert information defined in entity class form
class myentity { [...] /* * @assert\count(min="1", max="3") */ protected $myfield; [...] }
the purpose customize view. in example, display message said "you must enter between [min] , [max] items"
i var_dumped lot of variable in form_div_layout.html.twig i've tried explore formbuilder object haven't found this.
do know way achieve ?
ps: sorry poor english
edit after martin rios answer:
the goal not provide error message.
the final goal use these values construction of view.
for example, if use jquery plugin: sfprototypeman, can have "add item" link , "remove item".
if want disable "add item" link when collection reaches maximum size, need manipulate constraint property in javascript
i tried study plugin jsformvalidatorbundle didn't understood how works...
why don't validation in cookbook ?
is far more easier inside entities. , @ same time have benefit of not having entities coupled symfony.
# src/acme/blogbundle/resources/config/validation.yml acme\blogbundle\entity\myentity: properties: myfield: - count: min: 1 max: 3 minmessage: "you must specify @ least 1 item" maxmessage: "you cannot specify more {{ limit }} items"
make sure property validating collection's (i.e. array or object implements countable)
edited after edition of chakhâl : don't need overcomplicate things, if want access somewhere keep values in parameters.yml , custom form validation afaik cannot use variable defined in parameters.yml on validation otherwise easy.
but try keep in mind, forms forms, , views different things. if want keep things simple, pass min / max values additional template array, , define in parameters.yml. if need go deeper, inject them in custom validator , have them in single place (but sounds overcomplicating things bit in personal opinion)
Comments
Post a Comment