This topic is locked
[SOLVED]

 Conditional Validation

9/27/2010 3:06:17 AM
PHPRunner General questions
L
lummis author

I would like to be able to validate user input on the Add and Edit pages where the result is dependant on the value of another field.
The two fields concerned are named date_qualifier and date - date_qualifier has 5 values which, on the add/edit page, are selected by radio button. The value of date will vary but will depend on which date_qualifier value has been selected.
The date_qualifier values and the desired validation are detailed below:
Before - date value to be a year, eg 1800

After - date value to be a year, eg 1850

Circa - date value to be a year, eg 1825

Between - date value to be a range of years, eg 1800-1850

Anytime - date value to be blank, ie no user entry
Can this be achieved?
Brian

A
ann 9/28/2010

Brian,
use JavaScript Onload event to fill 'date - date_qualifier' field.

Here is just a sample:

var ctrl1 = Runner.getControl(pageid, 'date_qualifier');

var ctrl2 = Runner.getControl(pageid, 'date - date_qualifier');



function func() {

if (ctrl1.getValue()=='Before'){

ctrl2.addValidation({

regex: "(18|19|20)\d\d",

message: "The field should be a valid year",

messagetype: "Text"

});

}

};



ctrl1.on('change', func);
L
lummis author 9/28/2010

Many thanks Ann but I think that I may have accidentally misled you or I am misunderstanding something as the script is not working.
The two fields are 'date_qualifier' and 'date' and BOTH are in a table named 'data'. From reading the PHPRunner manual I believe that the first line "var ctrl" should call the table - is that the case?
I then need to validate the 'date' field dependant on which of the 5 options for the field 'date_qualifier' (Before, After, Circa, Between and Anytime) have been selected by radio button. Although I have a basic knowledge of scripts which enables me to see how they work, regretfully I am not too good at compiling them. I guess that I need an If statement for each of the 5 options and I think that I can work out the Regular Expressions needed except for the last case of Anytime which I need to test for no data entered in the 'date' field.
Can you give me a further sample script to meet my needs.
Regards
Brian

admin 9/29/2010

Brian,
I suggest to post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

L
lummis author 9/29/2010

Have now resolved my query and have posted the revised script below to help anyone else who would like to validate data based on the input of another field.
var ctrl1 = Runner.getControl(pageid, 'date_qualifier');

var ctrl2 = Runner.getControl(pageid, 'date');
function func() {

if (ctrl1.getValue()=='before'||'after'||'circa'){

ctrl2.addValidation({

regex: "^(15|16|17|18|19|20)[0-9][0-9]$",

message: "Invalid year",

messagetype: "Text"

});

}

if (ctrl1.getValue()=='between'){

ctrl2.addValidation({

regex: "^(15|16|17|18|19|20)[0-9][0-9]\-[0-9][0-9]$",

message: "Invalid date range, please re-enter using yyyy-yyyy",

messagetype: "Text"

});

}

if (ctrl1.getValue()=='any time'){

ctrl2.addValidation({

regex: "^$",

message: "The date field should be empty",

messagetype: "Text"

});

}

}
ctrl1.on('change', func);