我有一个查找列,当我添加新项目时,我需要将搜索信息显示到带有搜索栏的下拉列表中,我找到一个插件,允许我按需要显示列表,但我需要更换我自己列表的默认查找列表,我不知道怎么做(我不知道插入它的代码)。
优先使用javacript和JQuery。 谢谢
这是我用来拥有自动填充下拉列表的javascript
$( function() {
$.widget( "custom.combobox", {
_create: function() {
this.wrapper = $( "<span>" )
.addClass( "custom-combobox" )
.insertAfter( this.element );
this.element.hide();
this._createAutocomplete();
this._createShowAllButton();
},
_createAutocomplete: function() {
var selected = this.element.children( ":selected" ),
value = selected.val() ? selected.text() : "";
this.input = $( "<input>" )
.appendTo( this.wrapper )
.val( value )
.attr( "title", "" )
.addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
.autocomplete({
delay: 0,
minLength: 0,
source: $.proxy( this, "_source" )
})
.tooltip({
classes: {
"ui-tooltip": "ui-state-highlight"
}
});
this._on( this.input, {
autocompleteselect: function( event, ui ) {
ui.item.option.selected = true;
this._trigger( "select", event, {
item: ui.item.option
});
},
autocompletechange: "_removeIfInvalid"
});
},
_createShowAllButton: function() {
var input = this.input,
wasOpen = false;
$( "<a>" )
.attr( "tabIndex", -1 )
.attr( "title", "Show All Items" )
.tooltip()
.appendTo( this.wrapper )
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass( "ui-corner-all" )
.addClass( "custom-combobox-toggle ui-corner-right" )
.on( "mousedown", function() {
wasOpen = input.autocomplete( "widget" ).is( ":visible" );
})
.on( "click", function() {
input.trigger( "focus" );
// Close if already visible
if ( wasOpen ) {
return;
}
// Pass empty string as value to search for, displaying all results
input.autocomplete( "search", "" );
});
},
_source: function( request, response ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
response( this.element.children( "option" ).map(function() {
var text = $( this ).text();
if ( this.value && ( !request.term || matcher.test(text) ) )
return {
label: text,
value: text,
option: this
};
}) );
},
_removeIfInvalid: function( event, ui ) {
// Selected an item, nothing to do
if ( ui.item ) {
return;
}
// Search for a match (case-insensitive)
var value = this.input.val(),
valueLowerCase = value.toLowerCase(),
valid = false;
this.element.children( "option" ).each(function() {
if ( $( this ).text().toLowerCase() === valueLowerCase ) {
this.selected = valid = true;
return false;
}
});
// Found a match, nothing to do
if ( valid ) {
return;
}
// Remove invalid value
this.input
.val( "" )
.attr( "title", value + " didn't match any item" )
.tooltip( "open" );
this.element.val( "" );
this._delay(function() {
this.input.tooltip( "close" ).attr( "title", "" );
}, 2500 );
this.input.autocomplete( "instance" ).term = "";
},
_destroy: function() {
this.wrapper.remove();
this.element.show();
}
});
$( "#combobox" ).combobox();
$( "#toggle" ).on( "click", function() {
$( "#combobox" ).toggle();
});
} );
.custom-combobox {
position: relative;
display: inline-block;
}
.custom-combobox-toggle {
position: absolute;
top: 0;
bottom: 0;
margin-left: -1px;
padding: 0;
}
.custom-combobox-input {
margin: 0;
padding: 5px 10px;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div class="ui-widget">
<select id="combobox">
<option value="Accessory">Accessory</option>
<option value="Car">Car</option>
<option value="Option">Option</option>
</select>
</div>
当我检查I.E.上的元素时,我的脚本会生成此代码。 * 1
<div class="ui-widget">
<select id="combobox" style="display: none;">
<option value="Accessory">Accessory</option>
<option value="Car">Car</option>
<option value="Option">Option</option>
</select>
<span class="custom-combobox">
<input title="" class="custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left ui-autocomplete-input" autocomplete="off">
<a tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-button-icon-only custom-combobox-toggle ui-corner-right" role="button">
<span class="ui-button-icon ui-icon ui-icon-triangle-1-s"></span>
<span class="ui-button-icon-space"> </span>
</a>
</span>
</div>
这是SharePoint * 2上的lokkup信息的默认显示代码
<td width="350" class="ms-formbody" valign="top">
<!-- FieldName="Products"
FieldInternalName="Products"
FieldType="SPFieldLookup"
-->
<span dir="none">
<select title="Products" id="Products_139d7cd0-706c-47fd-82fd-d532bae457c3_$LookupField">
<option selected="selected" value="0">(None)</option>
<option value="2">Accessories</option>
<option value="1">Cars</option>
<option value="3">Options</option>
</select>
<br>
</span>
</td>
我需要用代码* 1替换de code * 2
示例(我在油漆上做过):
答案 0 :(得分:0)
这是自定义表单吗?如果是这样,您应该使用下拉列表中的ID来填充自定义插件下拉列表。 你应该编辑你的ASPX文件。
我这次刚做过。 这是代码,de div类ui-widget是使用一些CSS下拉的容器。 在您的DOM中是来自原始下拉列表的ID 看起来像:
ctl00_ctl44_g_*ID*_ff71_ctl00_Lookup
此ID是select标记的一部分。在select标签中有选项。使用ID,您应该将这些选项放入插件中。
因此,请确定插件接受的数据类型。阵列?选择/选项?
并将数据从ID转换为所需数据。
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<input id="nieuweKlant" type="button" value="Nieuwe Klant" onclick="openDialogEdit();" />
<H3 class="ms-standardheader">
<nobr>Klant</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<input id="verversKlanten" type="button" value="Ververs Klanten" onclick="getListItem();" />
<div class="ui-widget">
<SharePoint:FormField runat="server" id="ff7{$Pos}" ControlMode="Edit" FieldName="Klant" __designer:bind="{ddwrt:DataBind('i',concat('ff7',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Klant')}"/>
</div>
<SharePoint:FieldDescription runat="server" id="ff7description{$Pos}" FieldName="Klant" ControlMode="Edit"/>
<input id="klantgegevens" type="button" value="Klantgegevens" onclick="openDialogEdit();" />
</td>
</tr>