Nickz
Nickz

Reputation: 1880

YUI catch form submit

I'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

Upvotes: 1

Views: 4613

Answers (3)

Gabriel Lana
Gabriel Lana

Reputation: 1

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

Upvotes: 0

Nick Husher
Nick Husher

Reputation: 1884

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!

Upvotes: 2

Nick Husher
Nick Husher

Reputation: 1884

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
         }
    });
});

Upvotes: 4

Related Questions