I have a combobox, once I enter a % character in between characters or as a last character (e.g ba%ry or barr%) , upon debugging I am receiving an incorrect string, the % character does not anymore exist. Its seems that the combobox removes this character. But if I input it as a first character (e.g %arry) I am able to retrieve the correct string.
Please advice
12 Answers, 1 is accepted
I have tried to reproduce depicted issue, but to no avail. Here is a screencast of my test. Let me know if I am missing something.
Kind regards,Georgi Krustev
the Telerik team
Thanks for the response! What version Telerik.Web.Mvc.dll are you using? I am currently using Telerik.Web.Mvc.dll version 2010.3.1110.235. This was downloaded before from your site. I am only using the open source codes.
I have used our live demos to test the reported issue. Currently they run under SP1 Q3 release (version 2010.3.1318). I recommend you to download it and test with it.
Georgi Krustev
the Telerik team
I downloaded the demo project that you advised me to. Using that version, I performed a simple test
1. I modified the FirstLook.aspx by adding a simple form and a submit button (this will submit the value of the combobox)
<h3>ComboBox</h3>
<form>
<input type="submit" id="submitButton" name="submitButton" value="Submit" />
<%
= Html.Telerik().ComboBox()
.Name(
"ComboBox")
.AutoFill(Model.ComboBoxAttributes.AutoFill.Value)
.SelectedIndex(Model.ComboBoxAttributes.SelectedIndex.Value)
.BindTo(
new SelectList(Model.Products, "ProductName", "ProductName"))
.HtmlAttributes(
new { style = string.Format("width:{0}px", Model.ComboBoxAttributes.Width) })
.Filterable(filtering =>
{
if (Model.ComboBoxAttributes.FilterMode != 0)
{
filtering.FilterMode(
AutoCompleteFilterMode.StartsWith);
}
})
.HighlightFirstMatch(Model.ComboBoxAttributes.HighlightFirst.Value)%>
</form>
2. Modified the FirstLookController.cs to receive the value of the combobox
public ActionResult FirstLook(ComboBoxFirstLookModel model, string ComboBox)
{
model.AutoCompleteAttributes.Width = model.AutoCompleteAttributes.Width ?? 200;
model.AutoCompleteAttributes.HighlightFirst = model.AutoCompleteAttributes.HighlightFirst ??
true;
model.AutoCompleteAttributes.AutoFill = model.AutoCompleteAttributes.AutoFill ??
false;
model.AutoCompleteAttributes.AllowMultipleValues = model.AutoCompleteAttributes.AllowMultipleValues ??
true;
model.AutoCompleteAttributes.MultipleSeparator = model.AutoCompleteAttributes.MultipleSeparator ??
", ";
model.ComboBoxAttributes.Width = model.ComboBoxAttributes.Width ?? 200;
model.ComboBoxAttributes.SelectedIndex = model.ComboBoxAttributes.SelectedIndex ?? 0;
model.ComboBoxAttributes.HighlightFirst = model.ComboBoxAttributes.HighlightFirst ??
true;
model.ComboBoxAttributes.AutoFill = model.ComboBoxAttributes.AutoFill ??
true;
model.DropDownListAttributes.Width = model.DropDownListAttributes.Width ?? 200;
model.DropDownListAttributes.SelectedIndex = model.DropDownListAttributes.SelectedIndex ?? 0;
var nw = new Telerik.Web.Mvc.Examples.Models.NorthwindDataContext();
model.Products = nw.Products.ToList();
return View(model);
}
3. performed a debug at the FirstLookController.cs
4. Run the program and input the value of %Chai% in the combobox.
5.Click the Submit Button
RESULTS:
Results where the same, I only received the value of Chai (No % sign). One thing I noticed, in my querystring I have
"http://localhost:7777/combobox?submitButton=Submit&ComboBox-input=%25Chai%25&ComboBox=Chai". I noticed that there is a another control created ComboBox-input which has the correct value, though ComboBox should be my control.
Im using VS 2010 Microsoft Windows XP SP3. Please advise.
I tried looking into the telerik codes and found the problem.
In the telerik.combobox.js there is a function keypress(e).
function keypress(e) {
var key = e.keyCode || e.charCode;
if (key == 0 || $.inArray(key, $t.list.keycodes) != -1 || e.ctrlKey) return true;
// always set value. Select(item) will override it if needed.
setTimeout($.proxy(
function () { this.$input.val(this.$text.val()); }, this), 0);
resetTimer(
this);
}
Inside we update the hidden input which is the "ComboBox" with the value of the "ComboBox-input" using this linesetTimeout($.proxy(
function () { this.$input.val(this.$text.val()); }, this), 0);
the problem is that there is also this line before that
if
(key == 0 || $.inArray(key, $t.list.keycodes) != -1 || e.ctrlKey) return true;
Pressing shift + % passes this criteria which in effect, the code will not anymore reach the update statement.
To fix this, since I am using IE7 and the intended users are also using IE7, I just added the following: (Key 37 pertains to shift + % in IE7)
function keypress(e) {
var key = e.keyCode || e.charCode;
if (key != 37) {
if (key == 0 || $.inArray(key, $t.list.keycodes) != -1 || e.ctrlKey) return true;
}
// always set value. Select(item) will override it if needed.
setTimeout($.proxy(
function () { this.$input.val(this.$text.val()); }, this), 0);
resetTimer(
this);
}
I performed some testings and it now works perfectly for my need.
Thank you for the posted code samples.
Nevertheless I was not able to reproduce depicted issue with version 2010.3.1318 (SP1 Q3 2010). I have created a sample project in my attempt to replicate the problem. It is attached to this message.
Please let me know if I am missing something.
Georgi Krustev
the Telerik team
I tried the project that you provided and it did not work. What browser are you using? The issue occured due to different keystroke behaviors between browsers. As I mentioned last time, we have this line
if (key == 0 || $.inArray(key, $t.list.keycodes) != -1 || e.ctrlKey) return true;
the list of keycodes are provided in telerik.list.js which are
keycodes: [8, // backspace
9, // tab
13, // enter
27, // escape
37, // left arrow
38, // up arrow
39, // right arrow
40, // down arrow
35, // end
36, // home
46] // delete
Pressing shift + % is also equivalent to 37 in IE7. That is why it passes the condition $.inArray(key, $t.list.keycodes) != -1 and in result does not anymore reaches the code
//this updates the hidden field used in the telerik combobox
function () { this.$input.val(this.$text.val()); }, this), 0);
You can try it using IE7. I think you should be able to recreate the issue by that browser.
Thank you for the clarification.
I was able to observe the reported issue. I am glad to inform you that it was fixed.
For your convenience I have attached the modified JavaScript file.
I have updated your Telerik points.
Georgi Krustev
the Telerik team
I have a problem which seems to be likely to the one Barry had.
If I enter a value to the ComboBox (using IE8) which ends with a dot ("."), the dot gets removed and not posted back to the server.
For example "Mr. Prof." is posted and thus stored in the database as "Mr. Prof", which is wrong.
I am using 2011.1.315 and hoped to change my "hidden-textbox-workaround" with this release. I tried to fix it in the telerik.combobox.js with the value 46 (value for ".") for the key value in the keypress method, but it showed no effect. Maybe I am completely wrong there anyway..
Any suggestions on how to solve this ?
Best regards,
Kai
Thank you for reporting this issue.
I confirm this is a bug and it will be fixed with next official release of Telerik Components for ASP.NET MVC.
For your convenience I have attached telerik.list.min.js and telerik.combobox.min.js files which include the fix.
I have updated your Telerik points.
Hristo Germanov
the Telerik team
Great, thank you very much for the quick reply!