Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event "Click" generates a random result in Chrome (OK on other browsers) #252

Closed
locas13 opened this issue Dec 31, 2013 · 9 comments
Closed

Comments

@locas13
Copy link

locas13 commented Dec 31, 2013

Hi,

I found a random result with the management of the event click on the Chrome browser.

The following code generates a blank result on the property "ObjTarget.id" ​​random way (sometimes it works, other times not):

Event.observe( document, 'click', function( e ){
try {
    Event.stop(e);
    var ObjTarget = Event.element(e);
    console.log('@ OnClick -> ', ObjTarget.id);
    ...
}
...
}

On other browsers, it works perfectly.

The example of the attached picture shows the log with 7 consecutive clicks on the same button :

chrome_click_event

I am at your disposal for further tests if necessary

Best regards and Happy New Year to all,

Greg

@mariomc
Copy link
Contributor

mariomc commented Dec 31, 2013

Maybe you were triggering the click on a child element of the button, hence the no id on the target? Care to share a jsfiddle with an example code and markup?

@fabiosantoscode
Copy link
Contributor

The target element of an event is not guaranteed to have an ID. I don't find this strange.

It seems like you need to use findUpwardsBySelector (or another findUpwardsBy* function) to get to the element you really need.

@locas13 locas13 closed this as completed Jan 7, 2014
@locas13
Copy link
Author

locas13 commented Jan 7, 2014

Error found : The blank id is for the icon in the button, not the id button (the bug is fired when you click just in the icon) :

http://jsfiddle.net/EGQG3/17/

Bug on chrome browser and works perfectly on every other browsers ... strange ^^

@suskind
Copy link
Contributor

suskind commented Jan 7, 2014

Hi, don't trust in ev.target or (using Ink) Ink.Dom.Event_1.element() to make your actions. We/You never know how elements will be rendered by browsers. Try methods given by @fabiosantoscode or use Event.findElement(e, 'button'); It's a good practice

@mAiNiNfEcTiOn
Copy link
Contributor

@locas13
With the findUpwardsByTag: http://jsfiddle.net/EGQG3/18/
Or with the findElement : http://jsfiddle.net/EGQG3/20/ (this is much nicer!)

@mariomc
Copy link
Contributor

mariomc commented Jan 8, 2014

Given the example, it seems in a way you're trying to achieve event delegation.

It's a recurring subject in Javascript and Ink gives you some tools to handle this as the good examples shown.

To further extend this support, next release you'll be able to use the method 'on' with the syntax shown here: http://jsfiddle.net/EGQG3/22/

@mAiNiNfEcTiOn
Copy link
Contributor

:) Pretty awesome! Didn't know that... (living and learning)

@fabiosantoscode
Copy link
Contributor

... or you might want to just keep your button element in a closure and
avoid findUpwards* or event delegation altogether.

@locas13
Copy link
Author

locas13 commented Jan 8, 2014

Thank you very much for your feedback and highly responsive support, it works perfectly :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants