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.11k stars 801 forks source link

validateValueCallback return type should be optional #8729

Closed BarkerCreations closed 2 weeks ago

BarkerCreations commented 1 month ago

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

Bug

What is the current behavior?

Typing in the survey-angular-ui package requires validateValueCallback to return a SurveyError or descendant.

What is the expected behavior?

If the value is valid I should be able to return null

How would you reproduce the current behavior (if this is a bug)?

Provide the test code and the tested page URL (if applicable)

Test code (in my custom widget)

const onValidateQuestion = (): SurveyError => {
    // Invalid if there is no answer object
    if (question.isRequired && (!question.value || Object.keys(question.value).length === 0)) {
        return new AnswerRequiredError();
    }

    // Yes I know
    // @ts-ignore
    return null;
};

Specify your

JaneSjs commented 3 weeks ago

Hello @BarkerCreations, The survey.onValidateQuestion function doesn't actually expect any return value. If a value is invalid, please specify the options.error parameter to display a validation error message to a user.

Let me know what you think.