开发者

YUI catch form submit

I'开发者_JS百科m trying to use YUI to validate a radio button group on form submit and then do action x.

I’m new to YUI and its hard to find any examples.

Appreciate any advice, cheers.

EDIT: YUI 2.0


It would help to know which version of YUI you're using, since the APIs are wildly different. In YUI3, you could do something like this:

YUI().use('node', function(Y) {
    var form = Y.one('form');

    form.on('submit', function(evt) {
         var radioButtons = form.all('input[type=radio]');

         // do some validation

         if(!valid) {
             evt.preventDefault(); // prevents the form from submitting
             // show error messages
         }
    });
});


Doing this in YUI2 is a little more verbose, as YUI2 is a little closer to the metal.

Here's a jsfiddle example on how to capture form submission and perform validation.

Hope that helps!


For YUI 1 (first version) you can use evt.halt();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜