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

ComboBox holding onto focus

5 Answers 76 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 17 May 2011, 06:25 PM
I have an aspx page with a series of controls on it, several of which are RadComboBoxes. All of these have the MarkFirstMatch set to true. The goal is to be able to use a warehouse scanner to populate a field, and move onto the next one. The scanner automatically appends keyCode 13 (typically the enter key) to the end of all of it's inputs, so we're looking for this and using it to set focus to the next control in line.

The problem: If the combobox is left blank (i.e. it's focused and I hit enter), everything works fine (focus is given to the next control). If, however, I choose an item from the list/type in something I know will resolve to a valid selection, and then hit enter, the next control is highlighted as though it were given focus, but the initial control still actually has focus (and is similarly focused).

I'm fairly certain this is the result of focus being passed to the next control, and then reclaimed by the initial control when MarkFirstMatch takes effect, and modifies the comboboxes selection based on the input. I've tried short circuiting selection changed events, taking focus in selection changed, and other similar things to simply stop it from happening. The real pain is I need it to actually do the selection, but I also need the focus to change.

Any help would be much appreciated.

5 Answers, 1 is accepted

Sort by
0
Gimmik
Top achievements
Rank 1
answered on 17 May 2011, 06:57 PM
This sounds really tricky. I know nobody likes to think about doing this, but have you considered a design change? Based in the information you provided, I would have designed the application slightly differently. I would create one master input box near the top, and wire it up so that the "complete" command (Enter, in your case) moves the data to the correct area of the application. That box gets to keep focus the whole time. Is that possible? You can also change your scanner to use a better (more unique) "complete" command than "Enter." I wired mine up to use F8 when I designed a simple POS system.

Maybe if you post some screen shots or sample code I might be able to think of something else.

Hope this helps!
-Gimmik
0
John
Top achievements
Rank 1
answered on 17 May 2011, 07:38 PM
(Thanks for the quick response)

We've already done that once or twice (design change). Our first pass was trying to edit in a grid...it didn't last long.It's not really up to me to make the decision or not, and I don't think a design change is likely going to stick as a solution (though I'll bring it up).

There are a couple of "bad" ways to go about it, but I'd rather not (like in the save, matching SelectedText against each item in the ComboBoxes and Selecting the match. At this point it doesn't matter who gets focus. It works without MarkFirstMatch).

I'm not sure how source code would be particularly useful, as I don't think there is any way I can post anything complete enough to worthwhile without simultaneously losing my job :)

I posted a few cropped screen shots to give an idea of the flow I'm talking about. It should at least make the "They both look highlighted" thing make sense.

step1 - the form when you arrive at it
step2 - typed information into the first two fields, followed by enter each time.
step3.1 - I pressed down arrow + enter
step3.2 - I only pressed enter
0
John
Top achievements
Rank 1
answered on 17 May 2011, 08:05 PM
I'm still hoping someone here has a better idea, but for now our solution is:

- Remove MarkFirstMatch (so it defaults to false)
- In the JavaScript, before where we currently move focus, verify that the entered text matches an item in the combobox (without selecting it). This way we can stop them if they accidentally scan the wrong bar-code or something.
- If the item is in the combobox, it is safe to move focus, otherwise inform and await the correction.

- When the save button is hit, go through all comboboxes and select the right items.
- Continue on as normal.
0
Gimmik
Top achievements
Rank 1
answered on 17 May 2011, 09:19 PM
Hi John,

I wonder if focus might be getting messed up if the control is firing off a postback. Have you tried setting autopostback to false for your controls? Do everything client-side using AJAX and only postback when you hit "submit."
0
Vasssek
Top achievements
Rank 1
answered on 22 Sep 2011, 02:34 PM
Hello,

I don't know whether your issue has been solved or not. Anyway, take a look at this topic:
http://www.telerik.com/community/forums/aspnet-ajax/combobox/removing-combobox-focus.aspx

I recommend you to call it from timeout function...

Best regards

Vasssek
Tags
ComboBox
Asked by
John
Top achievements
Rank 1
Answers by
Gimmik
Top achievements
Rank 1
John
Top achievements
Rank 1
Vasssek
Top achievements
Rank 1
Share this question
or