Jump to content

need to throw validate flag only if no fields are filled


madcrazy1

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

/*

});

Archived

This topic is now archived and is closed to further replies.

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