Validating Multiple fields in Javascript (Ebase 4.4)

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

Validating Multiple fields in Javascript (Ebase 4.4)

#1

Postby Wai » Wed Jan 16, 2013 10:17 am

If you want to validate multiple form fields have been completed, you can create functions for doing this.

Code: Select all

// ----------------------------------------
// Function to validate an array of fields
// ----------------------------------------
function validateMandatoryFields(fields)
{
	var validatedFields = true;
	for each (var field in fields)
	{
		if (!validateMandatoryField(field))
		{			
			validatedFields = false;
		}
	}
	
	return validatedFields;
}

// ----------------------------------------
// Function to validate a field
// ----------------------------------------
function validateMandatoryField(field)
{
	var validatedField = true;
	
	if (!field.value)
	{		
		event.owner.addErrorMessage(field.labelText.text + " is mandatory", false);
		validatedField = false;
	}

	return validatedField;
}
Then call this from a script, for example:

Code: Select all

var valFields = [fields.COUNTRY_CD, fields.VM_NUMBER, fields.TRANS_DATE_FROM, fields.TRANS_DATE_TO];

if (!validateMandatoryFields(valFields)){
	event.stopExecution();
}
0 x

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

Re: Validating Multiple fields in Javascript (Ebase 4.4)

#2

Postby dvanhussel » Tue Feb 12, 2013 10:39 pm

Wai wrote:If you want to validate multiple form fields have been completed, you can create functions for doing this.

Code: Select all

// ----------------------------------------
// Function to validate an array of fields
// ----------------------------------------
function validateMandatoryFields(fields)
{
	var validatedFields = true;
	for each (var field in fields)
	{
		if (!validateMandatoryField(field))
		{			
			validatedFields = false;
		}
	}
	
	return validatedFields;
}

// ----------------------------------------
// Function to validate a field
// ----------------------------------------
function validateMandatoryField(field)
{
	var validatedField = true;
	
	if (!field.value)
	{		
		event.owner.addErrorMessage(field.labelText.text + " is mandatory", false);
		validatedField = false;
	}

	return validatedField;
}
Then call this from a script, for example:

Code: Select all

var valFields = [fields.COUNTRY_CD, fields.VM_NUMBER, fields.TRANS_DATE_FROM, fields.TRANS_DATE_TO];

if (!validateMandatoryFields(valFields)){
	event.stopExecution();
}
I'm implementing a similar script for validating if user input is a number or not. This in order to accumulate all invalid filled fields.
Unfortunately the script is not run at all, because the default Ebase 'this is not a number'-popup is shown. Setting 'skip validation' for the event does not stop this.

Is there a way to disable the default ebase-popups? I'd rather not change the field type to 'character', as it would generate errors when used with external resources.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#3

Postby Jon » Thu Feb 14, 2013 12:01 pm

No, there is currently no way to disable this basic type check on the client. We might add it as an option some time in the future.
0 x

User avatar
priyank
Ebase User
Posts: 10
Joined: Tue Sep 18, 2012 6:02 pm
Location: India
Contact:

Re: Validating Multiple fields in Javascript (Ebase 4.4)

#4

Postby priyank » Sat Feb 16, 2013 6:17 pm

dvanhussel wrote: I'm implementing a similar script for validating if user input is a number or not. This in order to accumulate all invalid filled fields.
Unfortunately the script is not run at all, because the default Ebase 'this is not a number'-popup is shown. Setting 'skip validation' for the event does not stop this.

Is there a way to disable the default Ebase-popups? I'd rather not change the field type to 'character', as it would generate errors when used with external resources.
dvanhussel, one way of getting away with external resources error is to have an additional field (character type) for display in Ebase and numeric field for computations. Get the value in character field, validate the value as required and populate the numeric field.
0 x

User avatar
dvanhussel
Ebase User
Posts: 161
Joined: Fri Oct 19, 2007 12:45 pm
Location: Haarlem, the Netherlands

Re: Validating Multiple fields in Javascript (Ebase 4.4)

#5

Postby dvanhussel » Thu Feb 28, 2013 9:31 am

Hi priyank,

Thanks for sharing your solution! I already figured out doing it like this. But I still would like it if it was possible to have an option to override the default client validations :D

David

priyank wrote:
dvanhussel wrote: I'm implementing a similar script for validating if user input is a number or not. This in order to accumulate all invalid filled fields.
Unfortunately the script is not run at all, because the default Ebase 'this is not a number'-popup is shown. Setting 'skip validation' for the event does not stop this.

Is there a way to disable the default Ebase-popups? I'd rather not change the field type to 'character', as it would generate errors when used with external resources.
dvanhussel, one way of getting away with external resources error is to have an additional field (character type) for display in Ebase and numeric field for computations. Get the value in character field, validate the value as required and populate the numeric field.
0 x


Who is online

Users browsing this forum: Bing [Bot] and 41 guests