根据标签类验证字段

我正在设置动态表单字段,管理员可以自己向表单添加问题,让我们不用担心添加 任何事情。</ p>

这些是相当简单的问题,将在ajax验证脚本中进行验证并修改为当前的错误消息。 (没有真正需要进行php验证,我很乐意添加这个,但我无法让cvalidation适用于动态添加的字段)</ p>

我遇到的问题是 针对自定义类我已经为每个都应用了所需类的字段添加了标签。 在这种情况下,它是“必需的标签”。 </ p>

我的猜测就是对标签进行全面检查.. </ p>

 'afterValidate'=&gt;“js:function(  form,data,hasError){
if(document.forms ['user-form'] .require-label.value ==''){
$('&lt; li&gt; Field不能为空&lt; / li&gt; ')。appendTo('#user-form_es _');
$('。required-label')。css('border-color','#a94442');
$('label [for = requiredField] ')。css('color','#a94442');
}
else {
$('。required-label')。css('border-color','#3c763d');
$('label [for = .required-label]')。css('color','#3c763d');
返回true;

}
}
</ code> </ pre>

但问题是该值与标签并列,而不是在它下面。它们都嵌套在表格组类中。</ p>

任何想法如何定位 这个标签类还是有更好的方法来解决这个问题吗?</ p>

编辑。应该注意到,obvi ous是添加输入元素所需。 问题是有单选按钮和下拉列表也可以标记为必需。 </ p>
</ div>

展开原文

原文

I'm setting up dynamic form fields that admins can add questions to the form themselves and have us not worry about adding anything.

These are fairly simple questions and are going to be validated just in the ajax validation script and amended to the current error message. (no real need for php validation, I'd love to add this but I just can't get the cvalidation working for fields that are added dynamically)

The issue I'm having is aiming at the custom class I've put in the label for every field that has the required class applied to it. In this case it's "required label".

My guess to just have a blanket look at the label is..

 'afterValidate'=>"js:function(form, data, hasError) {
    if(document.forms['user-form'].required-label.value == '') {
                    $('<li>Field cannot be blank</li>').appendTo('#user-form_es_');
                     $('.required-label').css( 'border-color', '#a94442 ' );
                    $('label[for=requiredField]').css('color','#a94442 ');
                }
                else {
                       $('.required-label').css( 'border-color', '#3c763d ' ) ;
                       $('label[for=.required-label]').css('color','#3c763d ');
                        return true;

                 }
}

But the issue is that the value sits alongside the label, not under it. They are all nested in a form-group class.

Any ideas how to target this label class or is there a better way to go about this?

Edit. Should have noted, the obvious thing is to add required to the input element. The issue is that there is radio buttons and dropdowns that can be marked as required too.

1个回答



你可以只在输入元素中添加所需的内容吗? </ p>

 &lt; input type =“text”name =“firstname”value =“John”required&gt; 
</ code> </ pre>
</ div>

展开原文

原文

You could just add required to the input element?

<input type="text" name="firstname" value="John" required>

duangewu5234
duangewu5234 我的问题是,这是在模型的验证之前运行,它并不完美,但我在lesat上尝试它的方式并排运行,我可以为错误添加一个通用消息。
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问