Jump to content

jQuery validation: event of placing error msg?

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...):


...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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...