Files
SSC/CMS_SC/WebUserControls/mod_autocompleteShort.ascx

112 lines
4.3 KiB
Plaintext

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="mod_autocompleteShort.ascx.cs" Inherits="CMS_SC.WebUserControls.mod_autocompleteShort" %>
<%if (false)
{ %>
<webopt:BundleReference ID="BundleReference1" runat="server" Path="~/Content/css" />
<webopt:BundleReference ID="BundleReference2" runat="server" Path="~/Content/themes/base/css" />
<%} %>
<style>
.ui-autocomplete {
max-height: 36em;
min-width: 20em;
overflow-y: auto;
/* prevent horizontal scrollbar */
overflow-x: hidden;
}
/* IE 6 doesn't support max-height
* we use height instead, but this forces the menu to always be this tall
*/
* html .ui-autocomplete {
height: 36em;
}
</style>
<script>
// funzione autocomplete
function set<%=txtSel.ClientID %>() {
//$("input").autocomplete({
$("#<%=txtSel.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "<%=txtServiceUrl.Text %>",
data: "{'prefixText':'" + request.term + "'}",
dataType: "json",
async: true,
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('#')[0],
val: item.split('#')[1]
}
}))
},
error: function (result) {
alert("Impossibile caricare i dati!");
}
});
},
select: function (e, i) {
$("#<%=hiddenFieldID.ClientID %>").val(i.item.val);
$("#<%=txtSel.ClientID %>").val(i.item.label);
document.getElementById('<%=btnSearch.ClientID%>').click();
},
minLength: <%=txtMinCharAutoCom.Text %>
});
}
// funzione x intercettare focusout...
function fcsOut<%=txtSel.ClientID %>() {
$("#<%=txtSel.ClientID %>").focusout(function () {
// controllo se hidden diverso da txtsel...
var str = $("#<%=txtSel.ClientID %>").val()
if (str.search($("#<%=hiddenFieldID.ClientID %>").val()) < 0) {
$("#<%=hiddenFieldID.ClientID %>").val($("#<%=txtSel.ClientID %>").val());
}
// chiamo search...
document.getElementById('<%=btnSearch.ClientID%>').click();
});
}
// aggancio evento doc pronto con jQuery...
$(function () {
set<%=txtSel.ClientID %>();
fcsOut<%=txtSel.ClientID %>();
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
$(function () {
// chiamate jquery da rieseguire post ajax update x partial page render
$(function () {
set<%=txtSel.ClientID %>();
fcsOut<%=txtSel.ClientID %>();
});
});
});
</script>
<%--controlli "principali"--%>
<asp:Panel runat="server" ID="pnlAC">
<div class="input-group input-group-sm">
<span class="input-group-btn" style="text-align: left;">
<asp:LinkButton runat="server" ID="btnSearch" CssClass="btn btn-primary btn-sm" OnClick="btnSearch_Click">
<i class="fa fa-search text-info"></i>&nbsp;
<asp:Label runat="server" ID="lblField" />
</asp:LinkButton>
</span>
<%--searchinput form-control artworkcopylookup--%>
<asp:TextBox runat="server" ID="txtSel" CssClass="searchinput form-control" OnTextChanged="txtSel_TextChanged" AutoPostBack="True" TextMode="SingleLine" AutoCompleteType="Search" />
<%--controlli "accessori"--%>
<asp:TextBox runat="server" ID="txtMinCharAutoCom" Text="2" Visible="false" Width="1em" />
<asp:TextBox runat="server" ID="txtServiceUrl" Text="Services/WS_data.asmx/Test" Visible="false" Width="1em" />
<span class="input-group-btn">
<asp:LinkButton runat="server" ID="lnkReset" class="btn btn-primary btn-sm" OnClick="lnkReset_Click"><i class="fa fa-undo"></i></asp:LinkButton>
</span>
</div>
<asp:TextBox runat="server" ID="hiddenFieldID" AutoPostBack="true" OnTextChanged="hiddenFieldID_TextChanged" ViewStateMode="Enabled" Width="0px" Font-Size="6pt" BackColor="Transparent" BorderStyle="None" Height="0px" />
</asp:Panel>
<style>
.ui-autocomplete-category {
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
}
</style>