Results 1 to 9 of 9

Thread: Radio/CheckBox event listener onClick fires twice on label

  1. #1
    Sencha User
    Join Date
    Feb 2010
    Location
    Netherlands
    Posts
    20
    Vote Rating
    0
      0  

    Default Radio/CheckBox event listener onClick fires twice on label

    Hey guys,

    I have a few Radio and Checkboxes, got a onClick event listener on them.
    When i click on the radio or CheckBox itself, it works perfect.
    Ben when i press on the label the event fires twice? That really messes up my program.

    Anyone knows about this? How can I prevent this from happening?
    Tried changing to onChange, then nothing happens at all. And with onBlur it fires alot of events with a delay.

    Hopefully anyone got a solution.
    Thanks, Kevin

  2. #2
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976
    Vote Rating
    131
      0  

    Default

    This is actually by design by the browser. Clicking the label fires a second click event on the radio so it checks automatically. As both bubble up, you can catch them both.

    Simple check the target, and if the target was the label, do nothing.

  3. #3
    Sencha User
    Join Date
    Feb 2010
    Location
    Netherlands
    Posts
    20
    Vote Rating
    0
      0  

    Default

    I feel stupid to ask, but can you give me a small example code?
    Tried a few checks but it doesn't work, google aint helping either.

    Here is a part of my code.
    There are all CheckBoxes in the answerVector

    Code:
    for(index=0; index<answerVector.size();index++) { answerVector.get(index).addListener(Events.OnClick, new Listener<FieldEvent>(){
    @Override public void handleEvent(FieldEvent be) { //Target check here be.getTarget() equals or == what? . . .
    Made a be.getTarget() == answerVector.get(index)
    But it says it cant compare a Element to a CheckBox.

    Thanks, Kevin

  4. #4
    Sencha User
    Join Date
    Feb 2010
    Location
    Netherlands
    Posts
    20
    Vote Rating
    0
      0  

    Default

    Anyone help me, please. I really need this, been searching google for a day.
    But I have no idea how i can check this!

  5. #5
    Sencha User
    Join Date
    Feb 2010
    Location
    Netherlands
    Posts
    20
    Vote Rating
    0
      0  

    Default

    *kick*
    Anyone?

  6. #6
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976
    Vote Rating
    131
      0  

    Default

    Code:
    answerVector.get(index).addListener(Events.OnClick, new Listener<FieldEvent>(){
     
    @Override public void handleEvent(FieldEvent be) { 
    
    if(be.getTarget().getTagName().equalsIgnoreCase("label")){
    return;
    }
    untested code. This should only give you a hint how to use it.

  7. #7
    Sencha User
    Join Date
    Feb 2010
    Location
    Netherlands
    Posts
    20
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by sven View Post
    untested code. This should only give you a hint how to use it.
    Works like a charm!
    Thank you.

  8. #8
    Ext GWT Premium Member
    Join Date
    Aug 2010
    Posts
    13
    Vote Rating
    0
      0  

    Default

    Brilliant - I was dealing with the same issue.

  9. #9
    Sencha User
    Join Date
    Dec 2016
    Posts
    1
    Vote Rating
    0
      0  

    Default

    I know this has been a very long time since there was an update to this thread. But is it possible to let me know if this issue can be seen in all browser and versions or just specific? I've tried clicking on the label but it doesn't seem to fire a second click event. However sometimes(very rarely) it does seem to happen. Which is why i was curious to know if this browser(version) specific.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •