[英]jQuery autocomplete and replicated input fields
Currently have a form for internal order creation. 当前具有用于内部订单创建的表单。
Part number fields are created by looping this 通过循环此来创建零件号字段
<input name="part[]" type="text" value="" class="pn-autocomplete" />
jQuery Autocomplete is used to display a list of the descriptions, but enter the part number in the box jQuery Autocomplete用于显示描述列表,但在框中输入零件号
<script>
$(function() {
$( ".pn-autocomplete" ).autocomplete({
source: "pn-json-2.php",
minLength: 2,
focus: function( event, ui ) {
$(this).val( ui.item.pn );
return false;
},
select: function( event, ui ) {
$(this).val( ui.item.pn );
return false;
}
})
.autocomplete( "instance" )._renderItem = function( ul, item ) {
return $( "<li>" )
.append( "<a>" + item.desc + "</a>" )
.appendTo( ul );
};
});
</script>
Issue: Only the first instance of the field is displaying entries. 问题:仅该字段的第一个实例显示条目。 All others are displaying similar dropdowns but without the text description and do not allow selecting of parts.
所有其他菜单都显示类似的下拉列表,但没有文本描述,并且不允许选择零件。
I'm sure the answer is simple, but I cannot figure out what I am doing wrong! 我敢肯定答案很简单,但是我无法弄清楚自己在做什么错!
You would have to override the widget factory method first. 您必须首先重写小部件工厂方法。 Try this,
尝试这个,
$.widget( "ui.autocomplete", $.ui.autocomplete, {
options: {
renderItem: null,
},
_renderItem: function( ul, item ) {
return $( "<li>" )
.append( "<a>" + item.desc + "</a>" )
.appendTo( ul );
},
});
and then initialize your autocomplete like this, 然后像这样初始化您的自动完成功能,
$(function() {
$( ".pn-autocomplete" ).autocomplete({
source: "pn-json-2.php",
minLength: 2,
focus: function( event, ui ) {
$(this).val( ui.item.pn );
return false;
},
select: function( event, ui ) {
$(this).val( ui.item.pn );
return false;
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.