Jump to content

jQuery validation: event of placing error msg?


hellsing

Recommended Posts

Hi All,

 

Could you guys suggest how to call a function to resize fieldsets to equal height when the validation plugin puts an error message?

I have a fancy form made of 3 fieldsets side by side, and a simple code makes their height equal. It goes like this:

function eqHgt(){	var hght = 0;	$('.column').each(function() {        // all fieldsets have 'column' class		if($(this).height() > hght) {			hght = $(this).height(); 		}	});	$('.column').height(hght);}

The form is validated by the jQuery Validation plugin. The problem is that when the plugin finds some invalid fields, it puts error messages in label elements under those fields and the content of the fieldset overflows. It would make the wrapping fieldset one or more lines higher, but it can't grow because my function eariler gave a fixed height to all the 3 fieldsets. In this situation it's useless if I run the eqHgt again because it looks for the tallest element without avail.

 

I tried to put a new line into my eqHgt function immediatelly after the 3rd line ($('.column').each...):

$('.column').height('auto');

...so in my logic it would let the fieldsets to grow to the size their content dictate and then record the new size but it doesn't work. I must say I have no idea why.

 

Maybe the problem is that I bound eqHgt to an improper event. I tried to use #myform.change, .column.change and in invalidHandler function of validation plugin.

 

Your help would be highly appreciated.

Link to comment
Share on other sites

You can add a console.log statement inside that function to output something to the console so at least you'll know when it gets called. You could also use a breakpoint for that. If you're setting the height of each column you should do that before the loop, not inside it.It looks like that plugin has an option called invalidHandler that you might be able to use as a callback for when things get marked invalid:http://jqueryvalidation.org/validate

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...