This question is locked. New answers and comments are not allowed.
Hi!
I am using a Telerik ComboBox for selecting some ID-values. I am using AutoCompleteFilterMode.Contains as FilterMode.
Here is a part of the view:
In certain situations I want the user to confirm that he/she realy wants to change the value of the ComboBox. This is handled by the OnChange event:
If the user press cancel in the confirmbox the ComboBox should go back and show the existing (previus) value.
This work fine most of the times.
The problem is when the user type in some letter in the ComboBox and use the AutoComplete feature. Then the ComboBox (as it should) will display only a subset of the available options.
If the user now choose not to change the value (by pressing cancel in the confirmbox), the ComBox should revert to the existing (previus) value. However, beacuse of the AutoComplete feature, this value is not in the current displaylist of the ComboBox.
Then this line:
It seem that the Telerik ComboBox is using the ComboBox.select(index) function to set this value. The index of existingIDvalue is perhaps 6 (unfiltered). But now, beacuse of the AutoComplete filtering, the ComboBox is only displaying 2 items, there will bee an "index out of range error".
Is there a way to handle this?
I just want the user to bee able to cancel the new value, even when using the AutoComplete feature.
Here is the model and controller used for this example:
I attached a complete demo-project.
Just run the project and type in "6" in the input-field next to the Existing button. Click on the Existing button.
Type in "o" in the ComboBox and then select "one" in the selectlist.
Press cancel in the confirmbox and you should get the error.
Hope you can help mee with some suggestions here.
Best Regards
Mikael
I am using a Telerik ComboBox for selecting some ID-values. I am using AutoCompleteFilterMode.Contains as FilterMode.
Here is a part of the view:
@Html.HiddenFor(model => model.ExistingID)@Html.Label(Model.ExistingID+"")<div> @{Html.Telerik() .ComboBox() .Name("ID") .Encode(false) .BindTo(Model.TestList) .AutoFill(false) .HighlightFirstMatch(true) .ClientEvents(events => events.OnChange("IDChange")) .Filterable(filter => filter.FilterMode(AutoCompleteFilterMode.Contains)) .Value(Model.ID.ToString()) .Render();}In certain situations I want the user to confirm that he/she realy wants to change the value of the ComboBox. This is handled by the OnChange event:
function IDChange(e) { var existingIDvalue = $("#ExistingID").val(); var currentIDvalue = $("#ID").val(); var currentIDctrl = $("#ID").data("tComboBox"); if (existingIDvalue == currentIDvalue) return; if (existingIDvalue > 0) { if (!confirm("Do you want to change the value?")) { currentIDctrl.value(existingIDvalue); } } return;}If the user press cancel in the confirmbox the ComboBox should go back and show the existing (previus) value.
This work fine most of the times.
The problem is when the user type in some letter in the ComboBox and use the AutoComplete feature. Then the ComboBox (as it should) will display only a subset of the available options.
If the user now choose not to change the value (by pressing cancel in the confirmbox), the ComBox should revert to the existing (previus) value. However, beacuse of the AutoComplete feature, this value is not in the current displaylist of the ComboBox.
Then this line:
currentIDctrl.value(existingIDvalue);
will generate an error: The objectet is null or undefined.It seem that the Telerik ComboBox is using the ComboBox.select(index) function to set this value. The index of existingIDvalue is perhaps 6 (unfiltered). But now, beacuse of the AutoComplete filtering, the ComboBox is only displaying 2 items, there will bee an "index out of range error".
Is there a way to handle this?
I just want the user to bee able to cancel the new value, even when using the AutoComplete feature.
Here is the model and controller used for this example:
namespace ComboBoxTest.Models{ public class HomeModel { public HomeModel() { SelectListItem li1 = new SelectListItem(); li1.Value = "1"; li1.Text = "One"; SelectListItem li2 = new SelectListItem(); li2.Value = "2"; li2.Text = "Two"; SelectListItem li3 = new SelectListItem(); li3.Value = "3"; li3.Text = "Three"; SelectListItem li4 = new SelectListItem(); li4.Value = "4"; li4.Text = "Four"; SelectListItem li5 = new SelectListItem(); li5.Value = "5"; li5.Text = "Five"; SelectListItem li6 = new SelectListItem(); li6.Value = "6"; li6.Text = "Six"; IList<SelectListItem> nrlist = new List<SelectListItem>(); nrlist.Add(li1); nrlist.Add(li2); nrlist.Add(li3); nrlist.Add(li4); nrlist.Add(li5); nrlist.Add(li6); TestList = new SelectList(nrlist, "Value", "Text"); } public int ID { get; set; } public int ExistingID { get; set; } public SelectList TestList { get; set; } }}namespace ComboBoxTest.Controllers{ public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult ExistingSupplier(int i) { HomeModel m = new HomeModel(); m.ID = i; m.ExistingID = i; return View("Combo",m); } public ActionResult NewSupplier() { HomeModel m = new HomeModel(); return View("Combo", m); } public ActionResult About() { return View(); } }}I attached a complete demo-project.
Just run the project and type in "6" in the input-field next to the Existing button. Click on the Existing button.
Type in "o" in the ComboBox and then select "one" in the selectlist.
Press cancel in the confirmbox and you should get the error.
Hope you can help mee with some suggestions here.
Best Regards
Mikael