Skip to content

Commit

Permalink
#9210 SurveyModel: renamings - onScrollingElementToTop, onIsAnswerCor…
Browse files Browse the repository at this point in the history
…rect (#9217)

* #9210 SurveyModel: renamings - onScrollingElementToTop, onIsAnswerCorrect
Fixes #9210

* #9210 - move obsolete args to old interface

* #9210 - fix build

* #9210 - fix getInCorrectAnswerCount

* #9210 SurveyModel: renamings - onScrollingElementToTop, onIsAnswerCorrect
Fixes #9210

* Add deprecation messages

* #9210 SurveyModel: renamings - onScrollingElementToTop, onIsAnswerCorrect
Fixes #9210

* #9210 - change code

---------

Co-authored-by: RomanTsukanov <[email protected]>
  • Loading branch information
novikov82 and RomanTsukanov authored Dec 30, 2024
1 parent b4bcd55 commit ccbc787
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
11 changes: 9 additions & 2 deletions packages/survey-core/src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ export class Question extends SurveyElement<Question>
/**
* A correct answer to this question. Specify this property if you want to [create a quiz](https://surveyjs.io/form-library/documentation/design-survey-create-a-quiz).
* @see SurveyModel.getCorrectAnswerCount
* @see SurveyModel.getInCorrectAnswerCount
* @see SurveyModel.getIncorrectAnswerCount
*/
public get correctAnswer(): any {
return this.getPropertyValue("correctAnswer");
Expand Down Expand Up @@ -1965,7 +1965,14 @@ export class Question extends SurveyElement<Question>
protected checkIfAnswerCorrect(): boolean {
const isEqual = Helpers.isTwoValueEquals(this.value, this.correctAnswer, this.getAnswerCorrectIgnoreOrder(), settings.comparator.caseSensitive, true);
const correct = isEqual ? 1 : 0;
const options = { result: isEqual, correctAnswer: correct, correctAnswers: correct, incorrectAnswers: this.quizQuestionCount - correct };
const incorrect = this.quizQuestionCount - correct;
const options = {
result: isEqual,
correctAnswers: correct,
correctAnswerCount: correct,
incorrectAnswers: incorrect,
incorrectAnswerCount: incorrect,
};
if (!!this.survey) {
this.survey.onCorrectQuestionAnswer(this, options);
}
Expand Down
32 changes: 24 additions & 8 deletions packages/survey-core/src/survey-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,17 +906,27 @@ export interface DynamicPanelGetTabTitleEvent extends DynamicPanelCurrentIndexCh
}
export interface IsAnswerCorrectEvent extends QuestionEventMixin {
/**
* The number of correct answers in a matrix where each row is considered as one quiz question.
* A Boolean property that specifies whether the answer is correct (`true`) or incorrect (`false`). Use the `options.question.value` and `options.question.correctAnswer` properties to check the answer.
*/
correctAnswers: number;
result: boolean;
/**
* The number of incorrect answers in a matrix where each row is considered as one quiz question.
* Obsolete. Use `options.correctAnswerCount` instead.
*/
incorrectAnswers: number;
correctAnswers?: number;
/**
* A Boolean property that specifies whether the answer is correct (`true`) or incorrect (`false`). Use the `options.question.value` and `options.question.correctAnswer` properties to check the answer.
* Obsolete. Use `options.incorrectAnswerCount` instead.
*/
result: boolean;
incorrectAnswers?: number;
}
export interface CheckAnswerCorrectEvent extends IsAnswerCorrectEvent {
/**
* The number of correct answers in a matrix where each row is considered as one quiz question.
*/
correctAnswerCount: number;
/**
* The number of incorrect answers in a matrix where each row is considered as one quiz question.
*/
incorrectAnswerCount: number;
}
export interface DragDropAllowEvent {
/**
Expand Down Expand Up @@ -967,9 +977,9 @@ export interface ScrollingElementToTopEvent {
*/
elementId: string;
/**
* A Boolean property that you can set to `true` if you want to cancel the scroll operation.
* Obsolete. Use `options.allow` instead.
*/
cancel: boolean;
cancel?: boolean;
/**
* Obsolete. Use `options.element` instead.
*/
Expand All @@ -979,6 +989,12 @@ export interface ScrollingElementToTopEvent {
*/
page?: PageModel;
}
export interface ScrollToTopEvent extends ScrollingElementToTopEvent {
/**
* A Boolean property that you can set to `false` if you want to cancel the scroll operation.
*/
allow: boolean;
}
export interface GetQuestionTitleActionsEvent extends QuestionEventMixin, GetTitleActionsEventMixin { }
export interface GetPanelTitleActionsEvent extends PanelEventMixin, GetTitleActionsEventMixin { }
export interface GetPageTitleActionsEvent extends PageEventMixin, GetTitleActionsEventMixin { }
Expand Down
36 changes: 26 additions & 10 deletions packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ import {
ShowingChoiceItemEvent, ChoicesLazyLoadEvent, GetChoiceDisplayValueEvent, MatrixRowAddedEvent, MatrixBeforeRowAddedEvent, MatrixRowRemovingEvent, MatrixRowRemovedEvent,
MatrixAllowRemoveRowEvent, MatrixDetailPanelVisibleChangedEvent, MatrixCellCreatingEvent, MatrixCellCreatedEvent, MatrixAfterCellRenderEvent, MatrixCellValueChangedEvent,
MatrixCellValueChangingEvent, MatrixCellValidateEvent, DynamicPanelModifiedEvent, DynamicPanelRemovingEvent, TimerPanelInfoTextEvent, DynamicPanelItemValueChangedEvent,
DynamicPanelGetTabTitleEvent, DynamicPanelCurrentIndexChangedEvent, IsAnswerCorrectEvent, DragDropAllowEvent, ScrollingElementToTopEvent, GetQuestionTitleActionsEvent,
DynamicPanelGetTabTitleEvent, DynamicPanelCurrentIndexChangedEvent, CheckAnswerCorrectEvent, DragDropAllowEvent, ScrollToTopEvent, GetQuestionTitleActionsEvent,
GetPanelTitleActionsEvent, GetPageTitleActionsEvent, GetPanelFooterActionsEvent, GetMatrixRowActionsEvent, GetExpressionDisplayValueEvent,
ServerValidateQuestionsEvent, MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent, PopupVisibleChangedEvent, ChoicesSearchEvent,
OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent
OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent,
ScrollingElementToTopEvent,
IsAnswerCorrectEvent
} from "./survey-events-api";
import { QuestionMatrixDropdownModelBase } from "./question_matrixdropdownbase";
import { QuestionMatrixDynamicModel } from "./question_matrixdynamic";
Expand Down Expand Up @@ -800,7 +802,12 @@ export class SurveyModel extends SurveyElementCore
/**
* An event that is raised to define whether a question answer is correct. Applies only to [quiz surveys](https://surveyjs.io/form-library/documentation/design-survey/create-a-quiz).
*/
public onIsAnswerCorrect: EventBase<SurveyModel, IsAnswerCorrectEvent> = this.addEvent<SurveyModel, IsAnswerCorrectEvent>();
public onCheckAnswerCorrect: EventBase<SurveyModel, CheckAnswerCorrectEvent> = this.addEvent<SurveyModel, CheckAnswerCorrectEvent>();
/**
* Obsolete. Use the [`onCheckAnswerCorrect`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onCheckAnswerCorrect) event instead.
* @deprecated
*/
public onIsAnswerCorrect: EventBase<SurveyModel, IsAnswerCorrectEvent> = this.onCheckAnswerCorrect;

/**
* An event that is raised when users drag and drop survey elements while designing the survey in [Survey Creator](https://surveyjs.io/survey-creator/documentation/overview). Use this event to control drag and drop operations.
Expand All @@ -810,7 +817,12 @@ export class SurveyModel extends SurveyElementCore
/**
* An event this is raised before a survey element (usually page) is scrolled to the top. Use this event to cancel the scroll operation.
*/
public onScrollingElementToTop: EventBase<SurveyModel, ScrollingElementToTopEvent> = this.addEvent<SurveyModel, ScrollingElementToTopEvent>();
public onScrollToTop: EventBase<SurveyModel, ScrollToTopEvent> = this.addEvent<SurveyModel, ScrollToTopEvent>();
/**
* Obsolete. Use the [`onScrollToTop`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onScrollToTop) event instead.
* @deprecated
*/
public onScrollingElementToTop: EventBase<SurveyModel, ScrollingElementToTopEvent> = this.onScrollToTop;

public onLocaleChangedEvent: EventBase<SurveyModel, {}> = this.addEvent<SurveyModel, {}>();

Expand Down Expand Up @@ -5389,15 +5401,16 @@ export class SurveyModel extends SurveyElementCore
passedRootElement?: HTMLElement,
onScolledCallback?: () => void
): any {
const options: ScrollingElementToTopEvent = {
const options: ScrollToTopEvent = {
element: element,
question: question,
page: page,
elementId: id,
cancel: false,
allow: true,
};
this.onScrollingElementToTop.fire(this, options);
if (!options.cancel) {
this.onScrollToTop.fire(this, options);
if (!options.cancel && options.allow) {
const elementPage = this.getPageByElement(element as IElement);
if (this.isLazyRendering && !!elementPage) {
let elementsToRenderBefore = 1;
Expand Down Expand Up @@ -7169,7 +7182,7 @@ export class SurveyModel extends SurveyElementCore
* For more information about quizzes, refer to the following tutorial: [Create a Quiz](https://surveyjs.io/form-library/documentation/design-survey/create-a-quiz).
* @returns The number of correct answers in a quiz.
* @see getQuizQuestionCount
* @see getInCorrectAnswerCount
* @see getIncorrectAnswerCount
*/
public getCorrectAnswerCount(): number {
return this.getCorrectedAnswerCountCore(true);
Expand All @@ -7192,7 +7205,10 @@ export class SurveyModel extends SurveyElementCore
return res;
}
public getInCorrectedAnswerCount(): number {
return this.getInCorrectAnswerCount();
return this.getIncorrectAnswerCount();
}
public getInCorrectAnswerCount(): number {
return this.getIncorrectAnswerCount();
}
/**
* Returns the number of incorrect answers in a quiz.
Expand All @@ -7201,7 +7217,7 @@ export class SurveyModel extends SurveyElementCore
* @returns The number of incorrect answers in a quiz.
* @see getCorrectAnswerCount
*/
public getInCorrectAnswerCount(): number {
public getIncorrectAnswerCount(): number {
return this.getCorrectedAnswerCountCore(false);
}
onCorrectQuestionAnswer(question: IQuestion, options: any): void {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17385,7 +17385,7 @@ QUnit.test("no scrolling to page top after focus a question on another page - ht

let log = "";
const qName = "question66";
survey.onScrollingElementToTop.add((s, o) => {
survey.onScrollToTop.add((s, o) => {
log += "->" + o.element.name;
});
survey.onCurrentPageChanged.add((s, o) => {
Expand Down

0 comments on commit ccbc787

Please sign in to comment.