JQuery validation in symfony 2

im trying to get jquery validation in my symfony 2 project for a long time. It works fine with default messages. But I can’t get messages there. There is a problem with the name of the inputs. When I try something like this:

rules: { xxx_backbundle_offerstype[title]: "required" },messages: { xxx_backbundle_offerstype[title]: "This field is required" } 

I get this error "missing statement after id". I think this is a JS bug, but I don't know how to solve it. Is it possible to use jquery inf symfony validation.

Thanks for any advice.

+4
source share
2 answers

try below, use single quotes

 rules: { 'xxx_backbundle_offerstype[title]': "required" },messages: { 'xxx_backbundle_offerstype[title]': "This field is required" } 
+3
source

If you embed your JavaScript in HTML, you can do this (at least I do it like this):

 rules: { '{{ form.foo.vars.full_name }}': 'required' }, messages: { '{{ form.foo.vars.full_name }}': 'This field is required!' } 

In this case, you do not have to update your script when updating the name of the form element.

+2
source

Source: https://habr.com/ru/post/1445112/


All Articles