...
<div id="divPOExistingProduct">
</div>
$("#divPOExistingProduct").dialog({
height: 500,
width: 700,
modal: true,
autoOpen: false,
draggable: false,
resizable: false,
open: function () { },
close: function () { $("#divPOExistingProduct").html(""); }
});
//"Add Existing" button
$("#addexisting-poproduct").click(function (e) {
e.preventDefault();
var link = '@(Url.Action("POExistingProductAddPopup", "PurchaseOrder", new { purchaseOrderId = Model.Id }))';
existingProductDialog.load(link);
existingProductDialog.dialog("open");
return false; });
...
View (dialog)
...
<tr>
<td class="adminTitle">
@Html.NopLabelFor(model => model.Name):
</td>
<td class="adminData">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</td>
</tr>
...
$("#Name").keypress(function () {
var productName = $("#Name").val(); //0 based length, so add 1
if (productName.length + 1 > 2)
{
//Do autocomplete functionality
$("#Name").autocomplete({ //Here is where issue starts
source: function (request, response) {
//Get available Products based on search parameter and map data
$.getJSON('@Url.Action("GetProducts", "PurchaseOrder")', { searchProduct: productName }, function (data) { response($.map(data, function (item) {
return { value: item.Name, id: item.Id };
}));
})
},
//Used to dictate actions when user selects an option within autocomplete
select: function (event, ui) {
//Check to see if user tried to select the "No results" option
if (ui.item.id == 0) {
//Do some house cleaning and alert user to mistake
alert("You must retry your search for a Product");
$("#Name").val("");
$("#ProductId").val("");
return false;
}
//Record ProductId
$("#ProductId").val(ui.item.id);
}
});
}
});