fix jscript x autocomplete

This commit is contained in:
Samuele E. Locatelli
2014-03-28 15:47:55 +01:00
parent e5ec89584a
commit d16afe3454
3 changed files with 28 additions and 54 deletions
+13 -39
View File
@@ -6,14 +6,15 @@
<%} %>
<script>
$(function () {
$("#<%=txtSelezione.ClientID %>").autocomplete({
function set<%=txtSel.ClientID %>()
{
$("#<%=txtSel.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "<%=txtServiceUrl.Text %>",
data: "{'keywordStartsWith':'" + request.term + "'}",
data: "{'prefixText':'" + request.term + "'}",
dataType: "json",
async: true,
success: function (data) {
@@ -26,55 +27,28 @@
}))
},
error: function (result) {
alert("Due to unexpected errors we were unable to load data");
alert("Impossibile caricare i dati!");
}
});
},
select: function (e, i) {
$("#<%=hiddenFieldID.ClientID %>").val(i.item.val);
$("#<%=txtSelezione.ClientID %>").val(i.item.label);
$("#<%=txtSel.ClientID %>").val(i.item.label);
$("#<%=btnPost.ClientID %>").click();
},
//minLength: 2
minLength: <%=txtMinCharAutoCom.Text %>
});
}
// aggancio evento doc pronto con jQuery...
$(function () {
set<%=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 () {
$("#<%=txtSelezione.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "<%=txtServiceUrl.Text %>",
data: "{'keywordStartsWith':'" + request.term + "'}",
dataType: "json",
async: true,
success: function (data) {
//response(data.d);
response($.map(data.d, function (item) {
return {
label: item.split('#')[0],
val: item.split('#')[1]
}
}))
},
error: function (result) {
alert("Due to unexpected errors we were unable to load data");
}
});
},
select: function (e, i) {
$("#<%=hiddenFieldID.ClientID %>").val(i.item.val);
$("#<%=txtSelezione.ClientID %>").val(i.item.label);
$("#<%=btnPost.ClientID %>").click();
},
//minLength: 2
minLength: <%=txtMinCharAutoCom.Text %>
});
set<%=txtSel.ClientID %>();
});
});
});
@@ -82,10 +56,10 @@
<%--controlli "principali"--%>
<div class="input-group">
<span class="input-group-addon">
<asp:Label runat="server" ID="lblField" Text="Cerca:" Font-Size="0.8em" AssociatedControlID="txtSelezione" />
<asp:Label runat="server" ID="lblField" Text="Cerca:" Font-Size="0.8em" AssociatedControlID="txtSel" />
<asp:Button runat="server" ID="btnPost" OnClick="btnPost_Click" Visible="false" Text="+" />
</span>
<asp:TextBox runat="server" ID="txtSelezione" CssClass="searchinput form-control" OnTextChanged="txtSelezione_TextChanged" AutoPostBack="True" TextMode="SingleLine" AutoCompleteType="Search" />
<asp:TextBox runat="server" ID="txtSel" CssClass="searchinput form-control" OnTextChanged="txtSel_TextChanged" AutoPostBack="True" TextMode="SingleLine" AutoCompleteType="Search" />
<asp:TextBox runat="server" ID="hiddenFieldID" AutoPostBack="true" OnTextChanged="hiddenFieldID_TextChanged" Visible="true" ViewStateMode="Enabled" Width="0em" Font-Size="6pt" BackColor="Transparent" BorderStyle="None" />
<%--controlli "accessori"--%>
<asp:TextBox runat="server" ID="txtMinCharAutoCom" Text="2" Visible="false" Width="1em" />
+13 -13
View File
@@ -46,13 +46,13 @@ namespace C2P.WebUserControls
if (!Page.IsPostBack)
{
defaultVal = "";
txtSelezione.Attributes["placeholder"] = placeholder;
txtSel.Attributes["placeholder"] = placeholder;
}
}
protected void txtSelezione_TextChanged(object sender, EventArgs e)
protected void txtSel_TextChanged(object sender, EventArgs e)
{
if (txtSelezione.Text.Trim() == "")
if (txtSel.Text.Trim() == "")
{
hiddenFieldID.Text = defaultVal;
_valore = defaultVal;
@@ -125,11 +125,11 @@ namespace C2P.WebUserControls
{
get
{
return txtSelezione.Text;
return txtSel.Text;
}
set
{
txtSelezione.Text = value;
txtSel.Text = value;
}
}
/// <summary>
@@ -191,7 +191,7 @@ namespace C2P.WebUserControls
{
set
{
txtSelezione.ToolTip = value;
txtSel.ToolTip = value;
}
}
@@ -202,7 +202,7 @@ namespace C2P.WebUserControls
{
set
{
txtSelezione.Width = Unit.Parse(string.Format("{0}em", value));
txtSel.Width = Unit.Parse(string.Format("{0}em", value));
}
}
/// <summary>
@@ -212,7 +212,7 @@ namespace C2P.WebUserControls
{
set
{
txtSelezione.Width = Unit.Parse(string.Format("{0}%", value));
txtSel.Width = Unit.Parse(string.Format("{0}%", value));
}
}
/// <summary>
@@ -220,7 +220,7 @@ namespace C2P.WebUserControls
/// </summary>
public void setFocus()
{
txtSelezione.Focus();
txtSel.Focus();
}
/// <summary>
/// permette di passare altri parametri di contesto al metodo invocato x autocomplete
@@ -229,11 +229,11 @@ namespace C2P.WebUserControls
{
get
{
return txtSelezione.AccessKey;
return txtSel.AccessKey;
}
set
{
txtSelezione.AccessKey = value;
txtSel.AccessKey = value;
}
}
/// <summary>
@@ -243,7 +243,7 @@ namespace C2P.WebUserControls
{
set
{
txtSelezione.TabIndex = value;
txtSel.TabIndex = value;
}
}
/// <summary>
@@ -259,7 +259,7 @@ namespace C2P.WebUserControls
protected void lnkReset_Click(object sender, EventArgs e)
{
// resetto selezione e ricerca!
txtSelezione.Text = "";
txtSel.Text = "";
hiddenFieldID.Text = defaultVal;
_valore = defaultVal;
if (eh_reset != null)
+2 -2
View File
@@ -49,13 +49,13 @@ namespace C2P.WebUserControls {
protected global::System.Web.UI.WebControls.Button btnPost;
/// <summary>
/// txtSelezione control.
/// txtSel control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtSelezione;
protected global::System.Web.UI.WebControls.TextBox txtSel;
/// <summary>
/// hiddenFieldID control.