This topic is locked

Validate dos fields are the same

2/1/2014 1:44:14 PM
PHPRunner General questions
N
notuo author

Hi.
I have a form to fill and I need to validate two fields to be the same as confirmation. (Student ID number)
I can do this in the Before record added, but my problem is: how to return to the page that also has some other fields already filled and not loose those?
If I use "window.history.back();" I get back with an empty form.
Any hint is appreciated.
Regards,

N
notuo author 2/3/2014

Well, I tried to follow this post answer: http://www.asprunner.com/forums/topic/20244-validation-on-3-text-fields-advanced/pageviewfindpostp68386
and is kind of working for me. The issue is the validation never happen. Mainly, I do the validation in the onload event (verified it works with all the alerts I put) but
ONLoad code:

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

var ctrl2 = Runner.getControl(pageid, 'tarjeta2');
ctrl2.addValidation('nosoniguales');
//alert('OnLoad1 |' + ctrl1.getValue() + "|" + ctrl2.getValue() + "|");
this.on('beforeSave', function(formObj, fieldControlsArr, pageObj){

//alert('OnLoad2 |' + ctrl1.getValue() + "|" + ctrl2.getValue() + "|");

if(ctrl1.getValue() != ctrl2.getValue() ) {

//alert('OnLoad3 |' + ctrl1.getValue() + "|" + ctrl2.getValue() + "|");

ctrl2.validate();

} else {

//alert('OnLoad4 |' + ctrl1.getValue() + "|" + ctrl2.getValue() + "|");

ctrl2.removeValidation('nosoniguales');

}

});


validation code: As I did the validation before, I just want to have the message displayed under the second field.



function iguales(sVal) {

return 'Deben ser iguales';

}


I even took the demo test function (as it suits my needs and just changed the message as follows:

function nosoniguales(sVal)

{

var regexp = /^[A-Z]{3}-[0-9]{4}$/;

if(!sVal.match(regexp))

return 'Deben ser iguales';

}


Neither code works.
Am I missing anything?
BTW. If I use any standard validation, it works fine. phpr 7 build 19454
Thanks for any idea,