survey-library icon indicating copy to clipboard operation
survey-library copied to clipboard

hasErrors() functions unaware of errors added manually by question.addError()

Open metaturso opened this issue 2 years ago • 3 comments

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

This is a bug report.

What is the current behavior?

Calling question.hasErrors() after adding one or more errors by calling question.addErrors() results in the custom errors being lost.

All variants of hasErrors() are only aware of the SurveyJS errors produced by validators.

What is the expected behavior?

My expectation is that calling question.hasErrors(), survey.hasPageErrors(), survey.hasCurrentPageErrors(), or survey.hasErrors() should preserve custom errors manually added to a question by calling addError().

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

Obtain the instance of a SurveyJS question and call addError() before calling any of the hasErrors() methods available.

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

Tested page URL: https://codesandbox.io/s/frosty-grass-cipyl9?file=/src/App.vue

Test code

const page = this.survey.activePage;
const question = this.survey.getQuestionByName("LastName");
question.addError("This is an error.");

console.log(`question has error sync result`, question.hasErrors());
console.log(`question has error async handle`, question.hasErrors((hasErrors) => {
  console.log(`question has error async result`, hasErrors);
}));

console.log(`page error sync result`, this.survey.hasPageErrors(page));

question.addError("This is another error.");
console.log(`survey has error sync result`, this.survey.hasErrors());
console.log(`survey has error async handle`, this.survey.hasErrors((hasErrors) => {
  console.log(`survey has error async result`, hasErrors);
}));

Specify your

  • browser: Firefox, this is not a browser issue.
  • browser version: 109.0b6
  • surveyjs platform (angular or react or jquery or knockout or vue): vue
  • surveyjs version: 1.9

metaturso avatar Dec 29 '22 04:12 metaturso