ComboBox holding onto focus

6 posts, 0 answers
  1. John
    John avatar
    5 posts
    Member since:
    Apr 2011

    Posted 17 May 2011 Link to this post

    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.
  2. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 17 May 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. John
    John avatar
    5 posts
    Member since:
    Apr 2011

    Posted 17 May 2011 Link to this post

    (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
  5. John
    John avatar
    5 posts
    Member since:
    Apr 2011

    Posted 17 May 2011 Link to this post

    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.
  6. Gimmik
    Gimmik avatar
    170 posts
    Member since:
    May 2011

    Posted 17 May 2011 Link to this post

    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."
  7. Vasssek
    Vasssek avatar
    143 posts
    Member since:
    Aug 2010

    Posted 22 Sep 2011 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017