surveyjs / survey-library

Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout.
https://surveyjs.io/form-library
MIT License
4.21k stars 815 forks source link

Is it possible to activate a custom validator via boolean props? #3615

Open jmlopezo opened 3 years ago

jmlopezo commented 3 years ago

Are you requesting a feature, reporting a bug or asking a question?

question

What is the current behavior?

Is it possible to activate a custom validator via props? as isRequired

     {
         "type": "text",
         "name": "email",
         "title": "Email",
         "isUnique": true,
     }

and...

functions isUnique(params){
.......
}

Survey
    .FunctionFactory
    .Instance
    .register("isUnique", isUnique);

}
andrewtelnov commented 3 years ago

@jmlopezo You can extend the library. You can add "isUnique" property into question and then write a code to make sure question value is unique. You can use survey.onValidateQuestion event.

survey.onValidateQuestion.add((sender, options) {
  if(options.question.isUnique) {
   //check that this question value is unique and set options.error if it is not
 }
});

Thank you, Andrew

jmlopezo commented 3 years ago

Great, Thanks @andrewtelnov