Hi,
I have a combobox and I need a functionality like this. If the user enter an itemcode which is not avilable in the list then it shoud clear that value when focusing out of the combo. I have mensioned my code bellow and please help me to get above.
@{Html.EJ()
.ComboBox("ItemCodes")
.AllowFiltering(true)
.ComboBoxFields(h => h.Text("ItemCode").Value("InputItemKey"))
.Query("new ej.Query().select(['InputItemKey','ItemCode']).take(50)")
.ClientSideEvents(h => h.Filtering("filtering_ItemCode").Change("setItemCodeComboValue"))
.Datasource((IEnumerable<Object>)ViewBag.Items)
.Placeholder("Select an Item Code")
.Width("200")
.Render();
}
function filtering_ItemCode(e) {
var query = new ej.Query().select(['ItemCode', 'InputItemKey']);
query = (e.text !== '') ? query.where('ItemCode', 'contains', e.text, true) : query;
e.updateData(e.model.dataSource, query);
}
function setItemCodeComboValue(args) {
var value = $("#ItemCodes").ejComboBox("model.value");
if (value != null) {
var array2;
var array = @Html.Raw(Json.Encode(@ViewBag.Items));
for (var i = 0; i < array.length; i++) {
if (array[i].InputItemKey == value) {
array2 = [array[i].ItemName, array[i].UnitAbbr, array[i].UCPrice, array[i].ItTypeCode];
}
}
var cmbItNms = $("#ItemNames").data("ejComboBox")
cmbItNms.option({ value: value });
$('#HdnUnitAbbr').val(array2[1]);
$('#HdnUCPrice').val(array2[2]);
$('#HdnItTypeCode').val(array2[3]);
}
}
Thank you
Kalum