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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。