LA_*_*LA_ 5 jquery jquery-validate twitter-bootstrap
有什么方法可以让用户仅使用Twitter的引导程序类型从预定义列表中选择值?理想情况下,每个文本值都应替换为某个数字值(如何使用select)。
例如:
var regionsList = ["value1", "value2", "value3"];
var regionsCodesList = [11, 12, 77];
$('#region').typeahead({ source: regionsList });
Run Code Online (Sandbox Code Playgroud)
用户应该只能输入value1,value2或value3,仅此而已。一旦提交表单等的值11,12,77应该相应地通过。
更新。我创建了自定义验证方法:
$.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");
Run Code Online (Sandbox Code Playgroud)
regionsList作为传递param。但这并不能很好地工作-如果用户使用鼠标从列表中选择该值,则不会隐藏错误消息。
尝试更新方法:
$('#region').typeahead({
// ....
"updater" : function bla(item) {
$('#region').val(item);
$("#myForm").validate().element("#region");
return item; }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1980 次 |
| 最近记录: |