简体   繁体   中英

How to dyamically adding Elements to Mootools Form.Validator?

Currently I am using Form.Validator from Mootools 1.2.5 and Mootools-More 1.2.5, but i am having a hard time validating an Element's input when dynamically injected into the DOM after ondomready. I was wonder if there's a way to attach Form.Validator's functionalities to the newly inject Elements?


UPDATE:

Using what @Dimitar suggested i was able to fix the issue. I use the build in function getFields to repopulate/attach events to the dynamic Elements. formValidatorObj.watchFields(formValidatorObj.getFields()); Hope this will help some Mootooler's in the future!

i am not a big -more users but looking at the source code on github, this seems like a good guess:

https://github.com/mootools/mootools-more/blob/master/Source/Forms/Form.Validator.js#L161

i guess you can pass any element - dynamically created or otherwise.

formValidatorObj.watchFields([someElsCollection]); // or from form.getElements or whatever.

// dynamically add a new field...
formValidatorObj.watchFields([new Element("input.required[value=John]").inject(formValidatorObj.element, "top")]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM