duanbei1598 2015-06-15 09:08
浏览 124
已采纳

jQuery: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). As you can see from this screenshot: enter image description here

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. My boss wants me to move that message under the select. Here is some code from the php-html page generation file:

<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>';
}
  • 写回答

2条回答 默认 最新

  • duanlou2917 2015-06-15 09:16
    关注

    You can use the errorPlacement option to change the positioning of the error message

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示