I have developed a coach view in which i am doing validations on button click. Either in case of validation success or failure the control stays on the page but for validation failure on specific fields, alerts are generated.
I have only attached a script directly with the coach which populates tw.system.coachValidation on the specific field in case there is any validation failed else it just stays at the page.
If i give an invalid input and the validation fails, i get the alerts on the input but when i again click on the button, it says: 'The state of the task or service has changed on the server. You might for example have opened the same task twice. Close this window and re-run the task.'
I have the option 'Fire Validation' property set to 'before' on coach. This is the script in the validation script activity.
if ( tw.local.NewPolicy.genderValue == "" || tw.local.NewPolicy.genderValue == null){ tw.system.addCoachValidationError(tw.system.coachValidation, "tw.local.NewPolicy.genderValue", "Please select the Gender"); }
function getAge(dateString) { var today = new Date(); var birthDate = new Date(dateString); var age = today.getFullYear() - birthDate.getFullYear(); var m = today.getMonth() - birthDate.getMonth(); if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { age--; } return age; }
if ( tw.local.NewPolicy.highestEducationValue == "" || tw.local.NewPolicy.highestEducationValue == null){ tw.system.addCoachValidationError(tw.system.coachValidation, "tw.local.NewPolicy.highestEducationValue", "Please select the level of Education");
if (tw.system.coachValidation.validationErrors.listLength == 0) { tw.local.AcceptBtnColor = true; tw.local.Quote = "Quote \r\n This is a Quote" }
If there is no validation failure, on return to screen i can click on the button as many times as i want and the coach will not get closed but, if/when the first time validation fails and there occur alert on the specific field which failed validation, once i hit the button again, the coach closes. I am unable to see what is going wrong. Any help would be highly appreciated.