| Page 1 of 1 | [ 8 posts ] |
|
I am using the latest version of YUI3, 3.6.0 pr4
I'm trying to add an click event to a button. I have the following button definition: Code: <button id="CancelButton" type="button">Cancel</button> Here is my JavaScript to add the click event: Code: YUI().use('event', 'button', function (Y) { var cancelButton = new Y.Button({ srcNode: '#CancelButton', on: { 'click': function (e) { window.location = '/'; } } }) .render(); }); When I click on the button it does nothing, it just posts back to the current page. Is my code wrong? |
Marco AsbreukYUI Contributor
|
Hey Brendan,
Better use Y.config.win instead of window. So it works in all browsers. Try this code and it should work Code: YUI().use('event', 'button', function (Y) { var cancelButton = new Y.Button({ srcNode: '#CancelButton', on: { 'click': function (e) { Y.config.win.location = '/'; } } }) .render(); }); Kind regards, Marco. |
|
Hi,
Thanks for the reply. I tried your code but the form is still posting to itself. I am using Microsoft's ASP.NET MVC. But this won't make the difference. I took everything off the page just to see if it wasn't maybe another element that was causing this issue. Then I had this: Code: <form action="/Application/Create" method="post"> <button id="SaveButton" type="submit">Save</button> <button id="CancelButton" type="button">Cancel</button> </form> If apply your code changes and click on cancel then the page submits to itself. If I take the button out of the <form></form> tags and place it outside of these tags then it works 100%. Have you any idea why this is like this? I just need it to redirect to another page, that's all, not submit itself. |
Marco AsbreukYUI Contributor
|
Hi Brendan,
Have you validated your html? That might be a problem. Take a look at this ticket: http://yuilibrary.com/forum/viewtopic.php?p=33884#p33884 Regards, Marco. |
|
Thanks.
I did an HTML validate and it did validate successfully. But I'm still stuck with this issue. I noticed that my buttons weren't in a form tag. Then it worked fine. Now I put them in a form tag and it is handling the cancel button as a submit button. I don't want it to be a submit button, just a plain button. You can try it yourself, I made a plain HTML page with just 2 buttons on it like this: Code: <!DOCTYPE html> <html> <head> <title>Test submit</title> </head> <body class="yui3-skin-sam"> <h1>Test submit</h1> <form action="/Administration/Department/Create2" method="post"> <button id="SaveButton" type="submit">Save</button> <button id="CancelButton" type="button">Cancel</button> </form> <script src="http://yui.yahooapis.com/3.6.0pr4/build/yui/yui-min.js"></script> <script> YUI().use('button', function (Y) { var saveButton = new Y.Button({ srcNode: '#SaveButton' }).render(); var cancelButton = new Y.Button({ srcNode: '#CancelButton', on: { 'click': function (e) { Y.config.win.location = '/Administration/Department/List'; } } }).render(); }); </script> </body> </html> Can you please see if you can create a simple page that redirects from 1 page to another? The buttons must be in form tag. |
|
Is there no one that can help me? Am I the only one in the whole wide world with this problem? Can someone please post a working solution to my problem. I've already stripped down the markup to a bare minimum. Is this maybe a YUI bug? Can someone from the YUI team have a look at this and get back to me? Doesn't the on click event work between form tags like the way that I have it?
|
|
I like this framework, although not so many features as YUI 2, so I don't want to revert to jQuery for my functionality.
|
Juan Ignacio DopazoYUI Contributor
|
Honestly, that last comment... not nice.
The code limits of the forum are driving me nuts. AnswerClick here to see the revision history on this Gist. |
| Page 1 of 1 | [ 8 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group