Jump to content

need to throw validate flag only if no fields are filled


Recommended Posts

 

I need code to throw validate flag only if no fields are filled

Current code below throws validate flag if any field is empty. Many thanks!

(a flag has a background of error.png

no flag has a background of checked.png)

 

	validates errors on all the fieldsets
records if the Form has errors in $('#formElem').data()
*/
function validateSteps(){
	var FormErrors = false;
	for(var i = 1; i < fieldsetCount; ++i){
		var error = validateStep(i);
		if(error == -1)
			FormErrors = true;
	}
	$('#formElem').data('errors',FormErrors);	
}

/*
validates one fieldset
and returns -1 if errors found, or 1 if not
*/
function validateStep(step){
	if(step == fieldsetCount) return;

	var error = 1;
	var hasError = false;
	$('#formElem').children(':nth-child('+ parseInt(step) +')').find(':input:not(button)').each(function(){
		var $this 		= $(this);
		var valueLength = jQuery.trim($this.val()).length;

		if(valueLength == ''){
			hasError = true;
			$this.css('background-color','#FFEDEF');
		}
		else
			$this.css('background-color','#FFFFFF');	
	});
	var $link = $('#navigation li:nth-child(' + parseInt(step) + ') a');
	$link.parent().find('.error,.checked').remove();

	var valclass = 'checked';
	if(hasError){
		error = 1;
		valclass = 'error';
	}
	$('<span class="'+valclass+'"></span>').insertAfter($link);

	return error;
}

/*

});

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.