【问题标题】:Twitter's bootstrap typeahead - how to allow values from the list only?Twitter 的 bootstrap typeahead - 如何只允许列表中的值?
【发布时间】:2012-06-20 17:31:41
【问题描述】:

是否有任何方法允许用户仅使用 Twitter 的引导程序预先输入来从预定义列表中选择值?理想情况下,每个文本值都应替换为某个数值(select 怎么可能)。

例如:

var regionsList = ["value1", "value2", "value3"];
var regionsCodesList = [11, 12, 77];
$('#region').typeahead({ source: regionsList });

用户应该只能输入 value1value2value3,仅此而已。提交表单后,应相应地传递 111277 等值。

更新。我创建了自定义验证方法:

$.validator.addMethod("validRegion", function (value, element, param) {
  return !(param.indexOf(value) == -1);
}, "Please start to input the region and then choose the value from the list");

regionsList 作为param 传递。但它效果不佳 - 如果用户用鼠标从列表中选择值,则不会隐藏错误消息。

【问题讨论】:

    标签: jquery jquery-validate twitter-bootstrap


    【解决方案1】:

    试试更新方法:

    $('#region').typeahead({ 
       // ....  
       "updater" : function bla(item) {
           $('#region').val(item);
           $("#myForm").validate().element("#region");
           return item;         }
       } 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      相关资源
      最近更新 更多