简体   繁体   English

jQuery:chzn-select的验证消息位置

[英]jQuery: validation message position for chzn-select

In a form of a web application I would like the message error validation to be showed under the select menu (in particular it is a chzn-select plugin menu). 我希望以Web应用程序的形式在选择菜单下显示消息错误验证(特别是chzn-select插件菜单)。 As you can see from this screenshot: 从此屏幕截图中可以看到: 在此处输入图片说明

it works for "Metodo Pagamento" select while it does not work for "Cliente" select and this because, I think, Cliente is a chzn-select menu. 它适用于“ Metodo Pagamento”选择,而不适用于“ Cliente”选择,这是因为,我认为Cliente是一个chzn-select菜单。 My boss wants me to move that message under the select. 我的老板要我在选择下移动该消息。 Here is some code from the php-html page generation file: 这是php-html页面生成文件中的一些代码:

<style>

 label[for="oggetto[]"] {
 padding: 76px 0px 0px 143px !important;
 }

 label[for="modalita_pagamento"] {  
 padding: 13px 0px 0px 130px !important;
 }

 div.selector {
 overflow: visible;
 }

 #filed-sel {
 padding: 19px !important;
 }

</style>

...

<p>
  <label>Cliente</label>
  <span class="field" id="filed-sel">
     <?php
        if (isset($progetto['id_cliente']))
          $sistema->clienti->selectMenuClienti($progetto['id_cliente']);
        else
          $sistema->clienti->selectMenuClienti(null);
     ?>
  </span>
</p>

...

<p>
  <label>Metodo pagamento</label>
  <span class="field" id="filed-sel">
     <?php
        if (isset($progetto['metodo_pagamento']))
        $sistema->progetti>setPagamentoMetodo($progetto['metodo_pagamento']);
        else
        $sistema->progetti->setPagamentoMetodo(null);
    ?>
  </span>
</p> 

...

public function selectMenuClienti($id_cli) {
    $list_cli = $this->allClienti("");
    echo '<select data-placeholder="Scegli un cliente..." id="client_prj"  name="client_prj" class="chzn-select">';
    echo '<option value=""></option>';

    for($i=0; $i<count($list_cli); $i++) {
        if (($id_cli != null) && ($id_cli == $list_cli[$i]["id"])) {
            echo '<option value="'.$list_cli[$i]["id"].'"  selected>'.$list_cli[$i]["id"].' - '.$list_cli[$i]["cognome"].' '.$list_cli[$i]["nome"].'</option>';
        }
        else {echo '<option value="'.$list_cli[$i]["id"].'">'.$list_cli[$i]["id"].' - '.$list_cli[$i]["cognome"].' '.$list_cli[$i]["nome"].'</option>';
        }
    }

    echo '</select>';
}

You can use the errorPlacement option to change the positioning of the error message 您可以使用errorPlacement选项更改错误消息的位置

errorPlacement: function (error, element) {
    //check whether chosen plugin is initialized for the element
    if (element.data().chosen) { //or if (element.next().hasClass('chosen-container')) {
        element.next().after(error);
    } else {
        element.after(error);
    }
}

Demo: Fiddle 演示: 小提琴

For example : $('#filed-sel').validate(); 例如:$('#filed-sel')。validate(); This is jquery validation. 这是jquery验证。 one more thing you just add jquery file also.. go through with url : http://www.runningcoder.org/jqueryvalidation/demo/ 您还需要添加jquery文件的另一件事..通过url进行访问: http : //www.runningcoder.org/jqueryvalidation/demo/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM