Skip to content

validateExpressions() returns internal validator instead of survey element + TS docs example is invalid #10840

@danlevison

Description

@danlevison

Describe the bug
The new SurveyModel.validateExpressions() API can return the ExpressionValidator object in IExpressionValidationResult.obj, but the documentation and TypeScript typings state that this value should be a survey element (question, panel, page, or survey).

Additionally, the documentation example does not compile in TypeScript because it accesses a non-existent name property on Base.

I took the example from - https://surveyjs.io/stay-updated/release-notes/v2.5.7

const results = survey.validateExpressions();
results.forEach(result => {
  const element = result.obj;

  console.warn(
    `Expression error in "${element.name}", property "${result.propertyName}":`,
    result.errors
  );
});
export interface IExpressionValidationResult {
  obj: Base;
  propertyName: string;
  errors: IExpressionError[];
}

See demo - https://codesandbox.io/p/devbox/keen-moser-ynk43n?file=%2Fsrc%2Fjson.js&workspaceId=ws_UBrjJL1E93iKDqX3Nj8Spq

At runtime, result.obj is not a survey element. It is an internal validator instance:

Expected behavior
Return the owning survey element when validators[] is used

result.obj should be the Question | Panel | Page | Survey that contains the expression

  • Browser: chrome
  • Browser version: 143.0.7499.192 (Official Build) (64-bit)
  • JS framework/library: React
  • SurveyJS version: v2.5.7
  • Device: PC

The current behaviour makes it difficult to display meaningful validation messages (e.g., element name) without relying on undocumented internal fields.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions