dqrqp8492 2016-03-08 11:15
浏览 50

根据标签类验证字段

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条回答 默认 最新

  • dourao1968 2016-03-08 12:47
    关注

    You could just add required to the input element?

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

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办