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.
source share