Spry验证可防止在不可用字段上提交表单

编程入门 行业动态 更新时间:2024-10-27 13:28:40
本文介绍了Spry验证可防止在不可用字段上提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在处理一个动态添加少量字段的表单,这些输入字段也有spry验证,因此表单在验证后提交。 如果不需要,也可以删除动态字段。 我使用jquery删除了这些字段,但在表单上不再可用,但使用相同的表单无法使用提交按钮提交。

I'm working on a form in which few fields are added dynamically, those input fields also have spry validations, so that form submit after validation. that dynamic fields can also be removed if not required. I removed that fields using jquery and no longer available on the form but doing the same form is unable to submit using submit button.

我尝试提交表单使用javascript form.submit()函数,表单已提交,但无法接收按钮变量。

I try to submit form using javascript form.submit() function, form submitted but button variable couldn't received.

那么如何禁用不可用字段的spry验证检查。

So How can I disable the spry validation check on the unavailable fields.

感谢您的回复,以便运作良好请为spry教程建议任何参考:)

Thanks for your reply thats work well please suggest any reference for spry tutorials :)

此外我想问我只使用以下内容来应用spry验证!

moreover I wanna ask I apply spry validation by just using the following!

var sprytextfield1 = new Spry.Widget。 ValidationTextField(sprytextfield_,none,{minChars:5,maxChars:10});

var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield_", "none", {minChars:5, maxChars:10});

但我只是破坏了sprytextfield1? 是否可以使用它或者必须使用其他方法!

but I m just destroy sprytextfield1? is it good to use it as or have to use other method!

还提到如何在多个字段上实现... 其中一些选择字段也是!

also mention how to implement on multiple fields... where some select fields are also!

推荐答案

如果您对要删除的元素有引用,Spry验证小部件有一个destroy()方法。

If you have a reference to the elements being removed, Spry validation widgets have a destroy() method.

以下代码显示了以一种微不足道的方式执行此操作:

The following code shows doing this in a trivial manner:

<!DOCTYPE html> <html> <head> <title>Notifications</title> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css"> <script> function clearValidation(){ if(sprytextfield1){ sprytextfield1.reset(); sprytextfield1.destroy() } } function reapplyValidation(){ sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {minChars:5, maxChars:10}); } </script> </head> <body> <form name="form1" method="post" action=""> <label for="sample"></label> <span id="sprytextfield1"> <label for="myField"></label> <input type="text" name="myField" id="myField"> <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldMinCharsMsg">Minimum number of characters not met.</span><span class="textfieldMaxCharsMsg">Exceeded maximum number of characters.</span></span> <input type="submit" name="submit" id="submit" value="Submit"> <input type="button" name="clear" id="clear" value="clear" onclick="clearValidation();" > <input type="button" name="reapply" id="reapply" value="reapply" onclick="reapplyValidation();" > </form> <script type="text/javascript"> var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {minChars:5, maxChars:10}); </script> </body> </html>

假设Spry文件与此页面所在的位置相同,当您加载在浏览器中的页面,如果您立即单击提交按钮,您应该看到验证消息。单击清除按钮将删除验证(我还添加了一个reset()调用以清除验证消息,但如果从页面中删除了您的字段及其验证消息包装,那么您可能不需要该部分)。然后单击提交按钮将允许页面正确提交。如果加载页面,则单击提交(查看验证消息),然后单击清除按钮(同时清除验证消息),然后单击重新应用按钮。然后提交按钮应显示验证。

Assuming you have the Spry files in the same location as this page looks for them, when you load the page in a browser, if you immediately click the submit button, you should see the validation message. Clicking the clear button will remove the validation (I also added a reset() call to clear the validation message, but if your fields and their validation message wrapper are removed from the page, then you may not need that part). Then clicking the submit button will allow the page to submit properly. If you load the page, then click submit (seeing the validation message) then click the clear button (also clearing the validation message), then click the Reapply button. Then the submit button should show the validation.

更多推荐

Spry验证可防止在不可用字段上提交表单

本文发布于:2023-10-30 01:19:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   表单   不可用   可防止   Spry

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!