Skip to content

Commit

Permalink
SurveyModel: Rename auto-advance properties fix #6796 (#9254)
Browse files Browse the repository at this point in the history
* Rename allowCompleteSurveyAutomatic -> autoAdvanceAllowComplete #6796

* Rename *goNextPageAutomatic into autoAdvanced #6796

* Update deprecation messages

---------

Co-authored-by: RomanTsukanov <[email protected]>
  • Loading branch information
andrewtelnov and RomanTsukanov authored Jan 7, 2025
1 parent 6ec2269 commit 6abb35d
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 182 deletions.
2 changes: 1 addition & 1 deletion packages/survey-core/src/base-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export interface IQuestion extends IElement, ISurveyErrorOwner {
onSurveyValueChanged(newValue: any): any;
updateValueFromSurvey(newValue: any, clearData: boolean): void;
updateCommentFromSurvey(newValue: any): any;
supportGoNextPageAutomatic(): boolean;
supportAutoAdvance(): boolean;
clearUnusedValues(): any;
getDisplayValue(keysAsText: boolean, value: any): any;
getValueName(): string;
Expand Down
4 changes: 3 additions & 1 deletion packages/survey-core/src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,9 @@ export class Question extends SurveyElement<Question>
public removeElement(element: IElement): boolean {
return false;
}
public supportGoNextPageAutomatic(): boolean {
// Obsolete
supportGoNextPageAutomatic(): boolean { return this.supportAutoAdvance(); }
public supportAutoAdvance(): boolean {
return false;
}
public supportGoNextPageError(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class QuestionBooleanModel extends Question {
isLayoutTypeSupported(layoutType: string): boolean {
return true;
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
return this.renderAs !== "checkbox";
}
public get isIndeterminate(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class QuestionDropdownModel extends QuestionSelectBase {
this.lastSelectedItemValue = selectedItemByValue;
}
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
return !this.isOtherSelected;
}
private minMaxChoices = <Array<ItemValue>>[];
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_imagepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class QuestionImagePickerModel extends QuestionCheckboxBase {
public getType(): string {
return "imagepicker";
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
return !this.multiSelect;
}
public get hasSingleInput(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export class QuestionMatrixModel
var loc = this.cells.getCellDisplayLocText(row, column);
return loc ? loc : this.emptyLocalizableString;
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
return this.isMouseDown === true && this.hasValuesInAllRows();
}
private errorsInRow: HashTable<boolean>;
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-core/src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
this.onSetQuestionValue();
this.updateIsAnswered();
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
var rows = this.generatedVisibleRows;
if (!rows) rows = this.visibleRows;
if (!rows) return true;
Expand All @@ -2078,7 +2078,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
var question = cells[colIndex].question;
if (
question &&
(!question.supportGoNextPageAutomatic() || !question.value)
(!question.supportAutoAdvance() || !question.value)
)
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_matrixdynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ export class QuestionMatrixDynamicModel extends QuestionMatrixDropdownModelBase
}
return res;
}
public supportGoNextPageAutomatic(): boolean {
public supportAutoAdvance(): boolean {
return false;
}
public get hasRowText(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_multipletext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ export class QuestionMultipleTextModel extends Question
protected isNewValueCorrect(val: any): boolean {
return Helpers.isValueObject(val, true);
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
for (var i = 0; i < this.items.length; i++) {
if (this.items[i].isEmpty()) return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_radiogroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class QuestionRadiogroupModel extends QuestionCheckboxBase {
public get clearButtonCaption() {
return this.getLocalizationString("clearCaption");
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
return this.isMouseDown === true && !this.isOtherSelected;
}
public getConditionJson(operator: string = null, path: string = null): any {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export class QuestionRatingModel extends Question {
public get questionName() {
return this.name + "_" + this.id;
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
return this.isMouseDown === true || this.renderAs === "dropdown";
}
public supportOther(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export class QuestionTextModel extends QuestionTextBase {
protected getIsInputTextUpdate(): boolean {
return this.maskTypeIsEmpty ? super.getIsInputTextUpdate() : false;
}
supportGoNextPageAutomatic(): boolean {
supportAutoAdvance(): boolean {
return !this.getIsInputTextUpdate() && !this.isDateInputType;
}
public supportGoNextPageError(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/questionnonvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class QuestionNonValue extends Question {
public getAllErrors(): Array<SurveyError> {
return [];
}
public supportGoNextPageAutomatic(): boolean {
public supportAutoAdvance(): boolean {
return false;
}
public addConditionObjectsByContext(
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export var settings = {
lifetime: 2000
},
/**
* Specifies how many milliseconds a survey should wait before it automatically switches to the next page. Applies only when [auto-advance](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#goNextPageAutomatic) is enabled.
* Specifies how many milliseconds a survey should wait before it automatically switches to the next page. Applies only when [auto-advance](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#autoAdvanceEnabled) is enabled.
*
* Default value: 300
*/
Expand Down
61 changes: 42 additions & 19 deletions packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class SurveyModel extends SurveyElementCore
* An event that is raised before the survey is completed. Use this event to prevent survey completion.
* @see onComplete
* @see doComplete
* @see allowCompleteSurveyAutomatic
* @see autoAdvanceAllowComplete
*/
public onCompleting: EventBase<SurveyModel, CompletingEvent> = this.addEvent<SurveyModel, CompletingEvent>();
/**
Expand All @@ -178,7 +178,7 @@ export class SurveyModel extends SurveyElementCore
* > Do not disable the [`showCompletePage`](https://surveyjs.io/form-library/documentation/surveymodel#showCompletePage) property if you call one of the `options.showSave...` methods. This is required because the UI that indicates data saving progress is integrated into the complete page. If you hide the complete page, the UI also becomes invisible.
* @see onPartialSend
* @see doComplete
* @see allowCompleteSurveyAutomatic
* @see autoAdvanceAllowComplete
*/
public onComplete: EventBase<SurveyModel, CompleteEvent> = this.addEvent<SurveyModel, CompleteEvent>();
/**
Expand Down Expand Up @@ -1550,7 +1550,7 @@ export class SurveyModel extends SurveyElementCore
* - `"top"` - Displays the navigation buttons above survey content.
* - `"both"` - Displays the navigation buttons above and below survey content.
* - `"none"` - Hides the navigation buttons. This setting may be useful if you [implement custom external navigation](https://surveyjs.io/form-library/examples/external-form-navigation-system/).
* @see goNextPageAutomatic
* @see autoAdvanceEnabled
* @see showPrevButton
* @see showCompleteButton
*/
Expand Down Expand Up @@ -1809,30 +1809,50 @@ export class SurveyModel extends SurveyElementCore
*
* Default value: `false`
*
* If you enable this property, the survey is also completed automatically. Set the [`allowCompleteSurveyAutomatic`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#allowCompleteSurveyAutomatic) property to `false` if you want to disable this behavior.
* If you enable this property, the survey is also completed automatically. Set the [`autoAdvanceAllowComplete`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#autoAdvanceAllowComplete) property to `false` if you want to disable this behavior.
*
* > If any of the following questions is answered last, the survey does not switch to the next page: Checkboxes, Yes/No (Boolean) (rendered as Checkbox), Long Text, Signature, Image Picker (with Multi Select), File Upload, Single-Select Matrix (not all rows are answered), Dynamic Matrix, Dynamic Panel.
*
* [View Demo](https://surveyjs.io/form-library/examples/automatically-move-to-next-page-if-answer-selected/ (linkStyle))
* @see [`settings.autoAdvanceDelay`](https://surveyjs.io/form-library/documentation/api-reference/settings#autoAdvanceDelay)
*/
public get goNextPageAutomatic(): boolean | "autogonext" {
return this.getPropertyValue("goNextPageAutomatic");
public get autoAdvanceEnabled(): boolean {
return this.getPropertyValue("autoAdvanceEnabled");
}
public set goNextPageAutomatic(val: boolean | "autogonext") {
this.setPropertyValue("goNextPageAutomatic", val);
public set autoAdvanceEnabled(val: boolean) {
this.setPropertyValue("autoAdvanceEnabled", val);
}
/**
* Specifies whether to complete the survey automatically after a user answers all questions on the last page. Applies only if the [`goNextPageAutomatic`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#goNextPageAutomatic) property is `true`.
* Obsolete. Use the [`autoAdvanceEnabled`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#autoAdvanceEnabled) property instead.
* @deprecated
*/
public get goNextPageAutomatic(): boolean {
return this.autoAdvanceEnabled;
}
public set goNextPageAutomatic(val: boolean) {
this.autoAdvanceEnabled = val;
}
/**
* Specifies whether to complete the survey automatically after a user answers all questions on the last page. Applies only if the [`autoAdvanceEnabled`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#autoAdvanceEnabled) property is `true`.
*
* Default value: `true`
* @see [`settings.autoAdvanceDelay`](https://surveyjs.io/form-library/documentation/api-reference/settings#autoAdvanceDelay)
*/
public get autoAdvanceAllowComplete(): boolean {
return this.getPropertyValue("autoAdvanceAllowComplete");
}
public set autoAdvanceAllowComplete(val: boolean) {
this.setPropertyValue("autoAdvanceAllowComplete", val);
}
/**
* Obsolete. Use the [`autoAdvanceAllowComplete`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#autoAdvanceAllowComplete) property instead.
* @deprecated
*/
public get allowCompleteSurveyAutomatic(): boolean {
return this.getPropertyValue("allowCompleteSurveyAutomatic");
return this.autoAdvanceAllowComplete;
}
public set allowCompleteSurveyAutomatic(val: boolean) {
this.setPropertyValue("allowCompleteSurveyAutomatic", val);
this.autoAdvanceAllowComplete = val;
}
/**
* Specifies when the survey validates answers.
Expand Down Expand Up @@ -6802,7 +6822,7 @@ export class SurveyModel extends SurveyElementCore
/**
* Sets a question value (answer).
*
* > This method executes all triggers and reevaluates conditions (`visibleIf`, `requiredId`, and others). It also switches the survey to the next page if the [`goNextPageAutomatic`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#goNextPageAutomatic) property is enabled and all questions on the current page have correct answers.
* > This method executes all triggers and reevaluates conditions (`visibleIf`, `requiredId`, and others). It also switches the survey to the next page if the [`autoAdvanceEnabled`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#autoAdvanceEnabled) property is enabled and all questions on the current page have correct answers.
* @param name A question name.
* @param newValue A new question value.
* @param locNotification For internal use.
Expand Down Expand Up @@ -6912,15 +6932,15 @@ export class SurveyModel extends SurveyElementCore
protected tryGoNextPageAutomatic(name: string) {
if (
!!this.isEndLoadingFromJson ||
!this.goNextPageAutomatic ||
!this.autoAdvanceEnabled ||
!this.currentPage
)
return;
var question = <Question>this.getQuestionByValueName(name);
if (
!question ||
(!!question &&
(!question.visible || !question.supportGoNextPageAutomatic()))
(!question.visible || !question.supportAutoAdvance()))
)
return;
if (!question.validate(false) && !question.supportGoNextPageError()) return;
Expand All @@ -6929,7 +6949,7 @@ export class SurveyModel extends SurveyElementCore
for (var i = 0; i < questions.length; i++) {
if (questions[i].hasInput && questions[i].isEmpty()) return;
}
if (this.isLastPage && (this.goNextPageAutomatic !== true || !this.allowCompleteSurveyAutomatic)) return;
if (this.isLastPage && (this.autoAdvanceEnabled !== true || !this.autoAdvanceAllowComplete)) return;
if (this.checkIsCurrentPageHasErrors(false)) return;
const curPage = this.currentPage;
const goNextPage = () => {
Expand Down Expand Up @@ -8367,17 +8387,20 @@ Serializer.addClass("survey", [
{ name: "maxTextLength:number", default: 0, minValue: 0 },
{ name: "maxCommentLength:number", default: 0, minValue: 0, alternativeName: "maxOthersLength" },
{
name: "goNextPageAutomatic:boolean",
name: "autoAdvanceEnabled:boolean", alternativeName: "goNextPageAutomatic",
onSetValue: function (obj: any, value: any) {
if (value !== "autogonext") {
value = Helpers.isTwoValueEquals(value, true);
}
obj.setPropertyValue("goNextPageAutomatic", value);
if(value === "autogonext") {
value = true;
}
obj.setPropertyValue("autoAdvanceEnabled", value);
}
},
{
name: "allowCompleteSurveyAutomatic:boolean", default: true,
visibleIf: (obj: any): boolean => obj.goNextPageAutomatic === true
name: "autoAdvanceAllowComplete:boolean", default: true, alternativeName: "allowCompleteSurveyAutomatic",
visibleIf: (obj: any): boolean => obj.autoAdvanceEnabled === true
},
{
name: "clearInvisibleValues",
Expand Down
22 changes: 11 additions & 11 deletions packages/survey-core/tests/question_matrixdynamictests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ QUnit.test("Matrixdropdown minRowCount", function (assert) {
rows[1].cells[0].question.value = "val2";
assert.equal(question.hasErrors(), false, "No errors, all rows have values");
});
QUnit.test("Matrixdropdown supportGoNextPageAutomatic property", function (
QUnit.test("Matrixdropdown supportAutoAdvance property", function (
assert
) {
var question = new QuestionMatrixDropdownModel("matrix");
Expand All @@ -1094,13 +1094,13 @@ QUnit.test("Matrixdropdown supportGoNextPageAutomatic property", function (
question.columns.push(new MatrixDropdownColumn("col2"));
var rows = question.visibleRows;
assert.equal(
question.supportGoNextPageAutomatic(),
question.supportAutoAdvance(),
false,
"There is no value in rows"
);
question.value = { row1: { col1: 1, col2: 11 } };
assert.equal(
question.supportGoNextPageAutomatic(),
question.supportAutoAdvance(),
false,
"There is no value in the second row"
);
Expand All @@ -1109,20 +1109,20 @@ QUnit.test("Matrixdropdown supportGoNextPageAutomatic property", function (
row2: { col1: 2, col2: 22 },
};
assert.equal(
question.supportGoNextPageAutomatic(),
question.supportAutoAdvance(),
true,
"All row values are set"
);
question.value = { row1: { col1: 1 }, row2: { col1: 2, col2: 22 } };
assert.equal(
question.supportGoNextPageAutomatic(),
question.supportAutoAdvance(),
false,
"The first row is not set completely"
);
});

QUnit.test(
"Matrixdropdown supportGoNextPageAutomatic always false for checkbox",
"Matrixdropdown supportAutoAdvance always false for checkbox",
function (assert) {
var question = new QuestionMatrixDropdownModel("matrix");
question.rows = ["row1", "row2"];
Expand All @@ -1139,12 +1139,12 @@ QUnit.test(
}
);

QUnit.test("Text date supportGoNextPageAutomatic false", function (assert) {
QUnit.test("Text date supportAutoAdvance false", function (assert) {
var question = new QuestionTextModel("text");
assert.equal(question.supportGoNextPageAutomatic(), true, "Suppored");
assert.equal(question.supportAutoAdvance(), true, "Suppored");
question.inputType = "date";
assert.equal(
question.supportGoNextPageAutomatic(),
question.supportAutoAdvance(),
false,
"Not suppored for date"
);
Expand All @@ -1157,13 +1157,13 @@ QUnit.test("Matrixdropdown set columns", function (assert) {
question.columns.push(new MatrixDropdownColumn("col2"));

assert.equal(
question.supportGoNextPageAutomatic(),
question.supportAutoAdvance(),
false,
"There is no value in rows"
);
question.value = { row1: { col1: 1, col2: 11 } };
assert.equal(
question.supportGoNextPageAutomatic(),
question.supportAutoAdvance(),
false,
"Checkbox doesn't support gotNextPageAutomatic"
);
Expand Down
10 changes: 5 additions & 5 deletions packages/survey-core/tests/question_ratingtests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1708,16 +1708,16 @@ QUnit.test("Generate empty rating in column", (assert) => {
assert.equal(col1.itemComponent, "sv-rating-item");
assert.equal(col2.itemComponent, "sv-rating-item-star");
});
QUnit.test("supportGoNextPageAutomatic", (assert) => {
QUnit.test("supportAutoAdvance", (assert) => {
const q1 = new QuestionRatingModel("q1");
q1.value = 1;
assert.equal(q1.supportGoNextPageAutomatic(), false, "#1");
assert.equal(q1.supportAutoAdvance(), false, "#1");
q1.onMouseDown();
assert.equal(q1.supportGoNextPageAutomatic(), true, "#2");
assert.equal(q1.supportAutoAdvance(), true, "#2");
q1.value = 2;
assert.equal(q1.supportGoNextPageAutomatic(), false, "#3");
assert.equal(q1.supportAutoAdvance(), false, "#3");
q1.displayMode = "dropdown";
assert.equal(q1.supportGoNextPageAutomatic(), true, "#4");
assert.equal(q1.supportAutoAdvance(), true, "#4");
});
QUnit.test("Check hasMin/MaxRateDescription properties on loading", (assert) => {
const survey = new SurveyModel({
Expand Down
Loading

0 comments on commit 6abb35d

Please sign in to comment.