Hi Experts,
I want a message if the city is not found in the dropdown list for that I am using textbox and jquery,
here is my code
index.cshtml
@Html.TextBoxFor(i => i.city, new { id = "Myid", @placeholder = "Your City", maxlength = 10, @class = "txt-small-50 ajax-select-cityList alphabetsonly", @required = true })
@Html.ValidationMessageFor(i => i.city)
$(function () {
$('#Myid').city({
// When user type something, onType event will fire.
onType: function (text) {
if (!this.currentResults.items.length) {
$('#cityNot').removeClass('hide');
} else {
$('#cityNot').addClass('hide');
}
}
});
});
$(function () {
$('#Myid').text({
// When user type something, onType event will fire.
onType: function (text) {
if (!this.currentResults.items.length) {
$('#cityNot').removeClass('hide');
} else {
$('#cityNot').addClass('hide');
}
}
});
});
Sachin SinghRank #66 · 26.2K reputationPosted May 2, 2022, 7:30 AM EDT
Jignesh KumarRank #91 · 22.9K reputationPosted May 2, 2022, 1:35 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted May 2, 2022, 4:35 AM EDT
Guest UserRank #3,125 · 458 reputationPosted May 2, 2022, 6:11 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted May 2, 2022, 6:29 AM EDT
$("#MyId").autocomplete({ source: function (request, response) { $.ajax({ url: yourUrl type: "get", dataType: "json", cache: false, success: function (data) { response($.map(data, function (item) { if (!ui.content.length) { var noResult = { value:"",label:"No results found" }; ui.content.push(noResult); $("#cityNot").removeClass("hide"); // here need to change } else { return { label:item.YourTextField, value: item.YourValueField } } })); } }); }, minLength: that.options.minLength, select: function (event, ui) { reRenderGrid(); } });You are not doing anything wrong, you just don't know about the plugin and how does that work.
Please share your autocomplete code.
Search your whole solution/ js file where your autocomplete is initializing.
search ($("Myid").autocomplete) word in your solution using ctrl+f and select the whole solution in the find dropdown of visual studio.
after that share the code.
Guest UserRank #3,125 · 458 reputationPosted May 2, 2022, 7:28 AM EDT
Guest UserRank #3,125 · 458 reputationPosted May 2, 2022, 7:34 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted May 2, 2022, 7:43 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts