• <tfoot id='5WMsv'></tfoot>

    <small id='5WMsv'></small><noframes id='5WMsv'>

    <legend id='5WMsv'><style id='5WMsv'><dir id='5WMsv'><q id='5WMsv'></q></dir></style></legend>
      <i id='5WMsv'><tr id='5WMsv'><dt id='5WMsv'><q id='5WMsv'><span id='5WMsv'><b id='5WMsv'><form id='5WMsv'><ins id='5WMsv'></ins><ul id='5WMsv'></ul><sub id='5WMsv'></sub></form><legend id='5WMsv'></legend><bdo id='5WMsv'><pre id='5WMsv'><center id='5WMsv'></center></pre></bdo></b><th id='5WMsv'></th></span></q></dt></tr></i><div id='5WMsv'><tfoot id='5WMsv'></tfoot><dl id='5WMsv'><fieldset id='5WMsv'></fieldset></dl></div>

          <bdo id='5WMsv'></bdo><ul id='5WMsv'></ul>

      1. 嗯.如何添加css“错误"在表单提交上输入的类?

        时间:2023-09-24
        • <small id='ymzKJ'></small><noframes id='ymzKJ'>

          <tfoot id='ymzKJ'></tfoot>
          • <bdo id='ymzKJ'></bdo><ul id='ymzKJ'></ul>
            <legend id='ymzKJ'><style id='ymzKJ'><dir id='ymzKJ'><q id='ymzKJ'></q></dir></style></legend>

              <tbody id='ymzKJ'></tbody>
          • <i id='ymzKJ'><tr id='ymzKJ'><dt id='ymzKJ'><q id='ymzKJ'><span id='ymzKJ'><b id='ymzKJ'><form id='ymzKJ'><ins id='ymzKJ'></ins><ul id='ymzKJ'></ul><sub id='ymzKJ'></sub></form><legend id='ymzKJ'></legend><bdo id='ymzKJ'><pre id='ymzKJ'><center id='ymzKJ'></center></pre></bdo></b><th id='ymzKJ'></th></span></q></dt></tr></i><div id='ymzKJ'><tfoot id='ymzKJ'></tfoot><dl id='ymzKJ'><fieldset id='ymzKJ'></fieldset></dl></div>
                  本文介绍了嗯.如何添加css“错误"在表单提交上输入的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有 Yii 表格.某些字段是必需的.提交表单时,我需要将 CSS 类错误"添加到文本输入中.我的代码:

                  I have Yii form. Some fields are required. When form is submitted i need that CSS class "error" would be added to the text input. My Code:

                            <?php $form=$this->beginWidget('CActiveForm', array(
                                      'id'=>'contact-form',
                                      'enableClientValidation'=>true,
                                      'clientOptions'=>array(
                                              'validateOnSubmit'=>true,
                                      ),
                              )); ?>
                             <ul class="contact_form">
                                 <li class="row">
                                     <?php echo $form->labelEx($model,'name'); ?>
                                     <?php echo $form->textField($model,'name', array('class'=>'input')); ?>
                                     <?php echo $form->error($model,'name'); ?>
                                 </li>
                  ...
                  

                  现在我只收到带有错误消息的 div:

                  Now i just get div with error message:

                  <div class="errorMessage" id="ContactForm_name_em_" style="">Laukelis Vardas, pavard" negali būti tuias.</div>
                  

                  如何将错误"类添加到输入字段?

                  How to add "error" class to input field?

                  推荐答案

                  要同时进行 AJAX 验证,您应该或多或少地添加如下内容:

                  To have AJAX validation also, you should add something more or less like this:

                  <?php $form=$this->beginWidget('CActiveForm', array(
                            'id'=>'contact-form',
                            'enableClientValidation'=>true,
                            'clientOptions'=>array(
                                'validateOnSubmit'=>true,
                                'afterValidate' => 'js:function(form, data, hasError) { 
                                    if(hasError) {
                                        for(var i in data) $("#"+i).addClass("error_input");
                                        return false;
                                    }
                                    else {
                                        form.children().removeClass("error_input");
                                        return true;
                                    }
                                }',
                                'afterValidateAttribute' => 'js:function(form, attribute, data, hasError) {
                                    if(hasError) $("#"+attribute.id).addClass("error_input");
                                        else $("#"+attribute.id).removeClass("error_input"); 
                                }'
                            ),
                          )); ?>
                  

                  这篇关于嗯.如何添加css“错误"在表单提交上输入的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 AppAsset 类中向 yii2 依赖项添加条件? 下一篇:Yii 中的多个 CJuiAutocomplete - 项目未呈现

                  相关文章

                  <small id='J3gaN'></small><noframes id='J3gaN'>

                    <legend id='J3gaN'><style id='J3gaN'><dir id='J3gaN'><q id='J3gaN'></q></dir></style></legend>
                    <i id='J3gaN'><tr id='J3gaN'><dt id='J3gaN'><q id='J3gaN'><span id='J3gaN'><b id='J3gaN'><form id='J3gaN'><ins id='J3gaN'></ins><ul id='J3gaN'></ul><sub id='J3gaN'></sub></form><legend id='J3gaN'></legend><bdo id='J3gaN'><pre id='J3gaN'><center id='J3gaN'></center></pre></bdo></b><th id='J3gaN'></th></span></q></dt></tr></i><div id='J3gaN'><tfoot id='J3gaN'></tfoot><dl id='J3gaN'><fieldset id='J3gaN'></fieldset></dl></div>
                    • <bdo id='J3gaN'></bdo><ul id='J3gaN'></ul>
                    <tfoot id='J3gaN'></tfoot>