This is a migrated thread and some comments may be shown as answers.

ComboBox retains value but not text on return to page

3 Answers 196 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ken Lewis
Top achievements
Rank 1
Ken Lewis asked on 10 Feb 2013, 05:27 AM
I created a couple of ComboBoxes and notice a strange thing if I do the following:

1. Select an item.
2. Navigate away from the page.
3. Use the browser's Back button to return to the page.

Upon returning, the ComboBox is blank (or the placeholder appears if I configured that). However, when I open the ComboBox, the item I had originally selected is highlighted. Thus, it appears that the value was retained though the text was not.

Is there any way to make sure the text retains its value on returning to the page?

(Note: I tried the same thing with a normal HTML select drop-down list, and the selected item remains selected upon return as expected.)

Thanks,

Ken

3 Answers, 1 is accepted

Sort by
0
David A.
Top achievements
Rank 1
answered on 01 Mar 2013, 05:30 AM
I'm having the same problem.  I have a search form that posts to a view containing a grid with the search results.  If I click the back button to edit my search criteria, the dropdownlist always displays the first item in the list.

Does anyone have a suggestion?

Thanks,
David A.
0
Ken Lewis
Top achievements
Rank 1
answered on 01 Mar 2013, 03:30 PM

David,

Here's the response I received from support:

-----
The value is not preserved because of the autocomplete attribute used on the text input. In order to preserve the text, you could change the attribute value through code after the combobox initialization:

$(function () {
    var combo = $("#comboID").data("kendoComboBox");
    combo.input.prop("autocomplete", "on");
});

but please note that this would also enable the browsers default auto-completion which may cause two popups to be shown when typing - one from the browser and one from the combobox.
-----

I tried that and I indeed saw the two popups, which is not desirable. However, the behavior is not all that reliable. Sometimes my combos retain their values just fine and sometimes not. It's unfortunate that the combo behavior is so non-standard.

I hope this helps get you closer to a workable solution.

Ken
0
David A.
Top achievements
Rank 1
answered on 01 Mar 2013, 04:59 PM
Ken, many thanks for taking the time to post a reply.  I will try the solution you posted, but a decent solution I ended up with was using the standard DropDownListFor and adding a style of "k-textbox" to it.  Added a little padding and the arrow from the sprite.png as the background image for Chrome, as it was not displaying the pulldown button.

David A.
Tags
ComboBox
Asked by
Ken Lewis
Top achievements
Rank 1
Answers by
David A.
Top achievements
Rank 1
Ken Lewis
Top achievements
Rank 1
Share this question
or