Friday, March 13, 2009

New: Client Side Javascript Validation plugin for Grails

So I created a grails plugin and i think it will be useful to everyone on a grails project.

So what does it do?

Well it is a client side javascript validator plugin that works with your existing constraints object. All you have to do is install it then put single tag on your page and you get instant javascript validation for your existing forms.

To install:

grails install-plugin javascript-validator


Next simply add this tag to your form page. This will show the errors as an alert box.

<jv:generate domain="book" form="bookForm" display="alert" />


Finally you then need to add an onsubmit event to your form. I may make this optional in the next release. But you need it for now.

<form action="/save" method="post" name="bookForm" id="bookForm" onsubmit="return validateForm(this);" >
...
</form>




If you want the error messages to show as list on the page do this:

<jv:generate domain="book" form="signUpForm" display="list" container="errors"/>



If you want validation on command objects then do this:


<jv:generate command="signUpCommand" controller="signUp" form="signUpForm" display="alert" />


<jv:generate command="signUpCommand" controller="signUp" form="signUpForm" display="list" container="errors"/>


That should get you going.

I need to write up the full documentation but will try to do that at the weekend. For now i am off to sleep.

Enjoy...

4 comments:

Website Design said...

I thought it was going to be some boring old post, but it really compensated for my time. I will post a link to this page on my blog. I am sure my visitors will find that very useful.

college board said...

Having read this post, I have learned for myself a lot of the new. Thanks

freelance academic writing said...

Thanks! This is a very good manual!

cheap research paper writing online said...

The best plugin for Javascript, I search it, thank you.