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 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services