Access a form control via it name?

Hello.

Is it possible to access a form control via its name, rather than it’s id?

It could be really useful. For example, when you try to implement a onValidationError function on the form, you get the form control key (= name) and not the id. By accessing the field config, I could display an error message box with the invalidMessage of that form control.

Actually, my only solution to do this is to have an form control id defined explicitly as equal to the form control name. Or build a JS method that would look through the form for each form control… Maybe it already exists? As the rules of a form are defined by using the form control name too.

Thanks in advance,

Jonathan Lannoy

Hello,

Name is a key property for the form elements. Basically, you can get any form control from the ‘elements’ array:

form.elements["name"]

http://webix.com/snippet/5ee99e09

If you know the form object, you can get any input inside the form like next

form.elements.inputName

$$("myform").elements.email.setValue("");

Or build a JS method that would look through the form for each form control.

There are form.clear(), form.setValues(), form.getValues() methods which affect all named inputs in the form.

Thank you, I achieved something cleaner ($$(‘myform’).elements[key].config.invalidMessage inside a onValidationError method).