验证隐藏字段

编程入门 行业动态 更新时间:2024-10-27 22:31:50
本文介绍了验证隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用MVC3进行无干扰的验证.我有一个字段,希望用户填充一些数据,然后按搜索"按钮.如果从未按下过搜索,或者用户在按下搜索后更改了输入字段,则该表格将无法提交.

I'm using MVC3 with unobtrusive validation. I have a field that the user is expected to fill with some data and then press a "search" button. If search has never been pressed or the user has changed the input field after pressing search, the form should not be possible to submit.

我添加了一个隐藏字段,该隐藏字段由按钮的click()事件设置为true,并由输入框的keyup()事件清空.现在,我想添加一个验证规则,该规则要求隐藏字段为true才能提交.

I've added a hidden field that is set to true by the click() event of the button and emptied by the keyup() event of the input box. Now I would like to add a validation rule that requires the hidden field to be true to allow submit.

优选地,我想使用非侵入式验证,但如果不起作用,则可以使用需要一些javascript的东西,只要它不会破坏表单其余部分的非侵入式验证即可.

Preferably I would like to use unobtrusive validation, but if that doesn't work it is ok with something that requires some javascript, as long as it doesn't spoil the unobtrusive validation for the rest of the form.

在添加type="hidden"之前,以下代码片段完全可以满足我的要求.

The following code snippet does exactly what I want, until I add type="hidden".

<input class="required" id="client-searched" data-val="true" name="ClientSearched" data-val-required="Press search!"/> <span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="ClientSearched"/>

推荐答案

尝试

var validator = $("#myFormId").data('validator'); validator.settings.ignore = "";

这是内容丰富的 博客文章

Here is an informative blog post

编辑

@RAM建议了更好的解决方案,请关注

@RAM suggested a better solution please FOLLOW

更多推荐

验证隐藏字段

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

发布评论

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

>www.elefans.com

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