简体   繁体   English

无需使用parsley.js即可使用提交按钮进行验证

[英]validate without having to use submit button using parsley.js

I want to use all the built in feature of parsley.js which is just specifying "required" in the tag like: 我想使用parsley.js的所有内置功能,只需在标记中指定“ required”即可,例如:

<asp:DropDownList ID="ddlmyid" runat="server" required>

The validation occurs after you would normally click on submit button and it validates. 验证将在您通常单击“提交”按钮并进行验证之后进行。 There is a popup message at the error which I like. 我喜欢的错误处弹出消息。

On my form I have a button that calls a server side function: 在我的表单上,我有一个调用服务器端函数的按钮:

<asp:LinkButton ID="btnSaveUpdate" runat="server" Text='Save' CommandName="SaveUp"
                            OnClick="SaveUpdate" Style="float: right;" />
  1. What is the best way to validate the form then call a server side function to process everything into the database 验证表单然后调用服务器端函数以将所有内容处理到数据库中的最佳方法是什么
  2. How can I integrate the normal form checking with this server side function call, instead of having to use the "submit" button? 如何将常规表单检查与此服务器端函数调用集成在一起,而不必使用“提交”按钮? I want it to validate the entire form when I click on the button that calls the server function. 当我单击调用服务器功能的按钮时,我希望它验证整个表单。
  3. I don't want to have to specify another type of error message and just use the default that came with Parsley. 我不想指定其他类型的错误消息,而只是使用Parsley附带的默认消息。 A few examples I have seen having to specify the message all over again with a div. 我已经看到一些示例,必须使用div重新指定消息。

Can I have a dummy submit button and call the onclick event, before calling my server side button event? 在调用服务器端按钮事件之前,可以有一个虚拟的提交按钮并调用onclick事件吗? Not sure how to do that... 不知道该怎么做...

thanks 谢谢

Partial Solution to What I am looking for: 我正在寻找的部分解决方案:

I am trying to implement this in a SharePoint webpart which poses additional challenges. 我正在尝试在SharePoint Webpart中实现这一点,这带来了其他挑战。
1. Registering the form with Parsley - Since it's in a SP web part which has a master page template, any local form tag gets removed since there is a master form tag called "aspnetForm". 1.在Parsley中注册表单-由于它位于具有母版页模板的SP Web部件中,因此将删除所有本地表单标签,因为存在一个名为“ aspnetForm”的主表单标签。 However, registering the form "aspnetForm" didn't seem to work too well. 但是,注册表格“ aspnetForm”似乎不太好。 I even tried to specify clientmodeid="static" so the form does get removed and then register the local form id, but Parsley can't seem to find this either. 我什至尝试指定clientmodeid =“ static”,以便删除表单,然后注册本地表单ID,但是Parsley似乎也找不到。 Lastly, I found this site: http://vogtland.ws/markedwardvogt/?p=1142 which shows it register it with "form". 最后,我找到了此站点: http : //vogtland.ws/markedwardvogt/?p=1142 ,显示该站点使用“表单”进行了注册。 Not sure why that works, but it does. 不知道为什么行得通,但是行得通。

  1. Then I use this very basic validation for parsley and change the function a little bit from the site mentioned above. 然后,我将这种非常基本的验证用于欧芹,并从上面提到的站点中对该函数进行一些更改。

     <script type="text/javascript"> function customValidation() { $('form').parsley(); if (!($('form').parsley().validate())) { alert("form is not valid2"); } else { alert("form is valid2"); } } </script> 
  2. The validation give an error message underneath the fields. 验证在字段下方给出错误消息。 But I want to use the nicer built in pop up message...does anyone know how I can do that? 但是我想使用更好的内置弹出消息...有人知道我该怎么做吗?

I've never used parsley.js - but they have to offer a way to perform validation manually (not from clicking submit). 我从未使用过parsley.js,但是他们必须提供一种手动执行验证的方法(而不是单击提交)。 OnClientClick attribute can be used to call a function in javascript before callin ganything in the server; OnClientClick属性可用于在服务器中调用ganything之前调用javascript中的函数;

<asp:LinkButton ID="btnSaveUpdate" runat="server" Text='Save' CommandName="SaveUp" 
         OnClientClick="validateForm();" OnClick="SaveUpdate" Style="float: right;" />

then something like 然后像

<script type="text/javascript">
function validateForm(){
  // parsley.js has this function from their docs
  // it prevents submission if not valid
  validate(group, force)

}

</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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