【问题标题】:bootstrap selectpicker dynamic select not posting selected value引导选择选择器动态选择不发布所选值
【发布时间】:2015-08-08 05:14:22
【问题描述】:

我有两个引导选择器,其中一个根据第一个动态填充选项。该部分似乎工作正常,但是,当我发布表单时,第二个选项的选定选项没有设置。无论您选择什么,它都只会选择列表中的第一项。

我使用了 selectpicker.refresh() 以便正确填写选择中的值。这是我填充动态选择的代码:

jQuery("#field_c7vkw42").empty(); //To reset courts
jQuery("#field_c7vkw42").append("<option value=''>--Select--</option>");
jQuery(arr).each(function(i) { //to list counties
jQuery("#field_c7vkw42").append("<option value=\"" + arr[i].value +  "\">" + arr[i].display + "</option>")
jQuery('#field_c7vkw42').selectpicker('refresh');

如果您想查看实时表格https://funnydriving.com/aaabbb/,请在第 2 步选择球场。现在我有它要验证,所以无论你选择什么你都会看到它认为它是空的?

【问题讨论】:

    标签: twitter-bootstrap bootstrap-select


    【解决方案1】:

    好的,所以我相信我终于知道发生了什么,以防将来有人遇到这个问题。事实证明,jquerybootstrapvalidation.js (http://ReactiveRaven.github.com/jqBootstrapValidation) 具有在提交表单时清除任何旧帮助消息框的功能:

    //for remove old error helpblock start
    $inputs.each(function (i, el) {
    var $this = $(el),
    $controlGroup = $this.parents(".control-group").first(),
    $helpBlock = $controlGroup.find(".help-block").first();             
    $this.trigger('change');
    

    如您所见,它触发了每个表单元素的“更改”。这实际上是在重置我的第二个动态框,因为它认为对第一个选择进行了更改。

    【讨论】:

      猜你喜欢
      • 2016-10-11
      • 1970-01-01
      • 2013-06-22
      • 1970-01-01
      • 2017-11-15
      • 1970-01-01
      • 2017-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多