I have
given three color for code. Red indicated
that it is mandatory. Black indicates comment and green indicates custom code.
if( typeof(
SiebelAppFacade.ValidatePR ) === "undefined" ){
SiebelJS.Namespace( "SiebelAppFacade.ValidatePR" );
SiebelApp.S_App.RegisterConstructorAgainstKey(
"ValidatePRenderer", "SiebelAppFacade.ValidatePR" );
SiebelAppFacade.ValidatePR = ( function(){
function ValidatePR( pm ){
SiebelAppFacade.ValidatePR.superclass.constructor.call( this, pm );
this.GetPM().AttachPMBinding(
"isEmailSet", validateEmail, {
scope: this });
/*
This is very important. We bing “isEmailSet”
variable. So that this will track changes in this variable in physical model. and
if changes happed, then validateEmail
will execute. */
}
SiebelJS.Extend( ValidatePR,
SiebelAppFacade.PhysicalRenderer );
function
validateEmail() {
var
controls = this.GetPM().Get( "GetControls" );
var cntrl = controls[
"EmailAddress" ];
/*The controls[
"EmailAddress" ]; will return an object that contain all information about
EmailAddress*/
var emailcntrl =
cntrl.GetInputName();
/*cntrl.GetInputName(); Using the above object getting input
name */
var
email = $('input[name="'+emailcntrl+'"]').val();
/*Here is jQuery!!... using our input name we are reading
the value in it. */
alert(email);
var
emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(
!emailReg.test( email ) ) {
alert("Please
enter a valid Email");
return
false;
}
else {
alert("This
is a valid Email");
return
true;
}
/*Using a regular expression, we are testing whether it is a
valid email or not.. old browser script.. */
}
return
ValidatePR;
}());
}
Now if you change value in email field, will trigger
Physical Model.. then Physical render and email filed will get validated. Hope you understand… :)






