如何动态添加元素到Mootools Form.Validator?

发布于 2024-11-02 16:47:37 字数 358 浏览 8 评论 0原文

目前我正在使用 Mootools 1.2.5 和 Mootools-More 1.2.5 中的 Form.Validator,但是在 ondomready 后动态注入到 DOM 中时,我很难验证元素的输入。我想知道是否有办法将 Form.Validator 的功能附加到新注入的元素上?


更新:

使用@Dimitar的建议我能够解决这个问题。我使用内置函数 getFields 将事件重新填充/附加到动态元素。 formValidatorObj.watchFields(formValidatorObj.getFields()); 希望这对将来的 Mootooler 有所帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林很绿却致人迷途 2024-11-09 16:47:37

我不是一个大用户,但查看 github 上的源代码,这似乎是一个不错的猜测:

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

我猜您可以传递任何元素 - 动态创建或以其他方式创建。

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")]);

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")]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文