Skip to content

Commit

Permalink
Rename hideNumber question proprty to showNumber fix #5230 (#9273)
Browse files Browse the repository at this point in the history
* Rename hideNumber question proprty to showNumber fix #5230

* Update deprecation messages

---------

Co-authored-by: RomanTsukanov <[email protected]>
  • Loading branch information
andrewtelnov and RomanTsukanov authored Jan 10, 2025
1 parent 37787f0 commit 71634db
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 34 deletions.
36 changes: 24 additions & 12 deletions packages/survey-core/src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,26 +494,36 @@ export class Question extends SurveyElement<Question>
}
/**
* Returns the visible index of the question in the survey. It can be from 0 to all visible questions count - 1
* The visibleIndex is -1 if the title is 'hidden' or hideNumber is true
* The visibleIndex is -1 if the title is 'hidden' or showNumber is false
* @see titleLocation
* @see hideNumber
* @see showNumber
*/
public get visibleIndex(): number {
return this.getPropertyValue("visibleIndex", -1);
}
public onHidingContent(): void { }
/**
* Hides the question number from the title and excludes the question from numbering.
* Specifies whether to show a number for this question. Setting this property to `false` hides the question number from the title and excludes the question from numbering.
*
* If you want to disable question numbering in the entire survey, set `SurveyModel`'s `showQuestionNumbers` property to `false`.
* @see SurveyModel.showQuestionNumbers
* Default value: `false` (inherited from the `SurveyModel`'s [`showQuestionNumbers`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#showQuestionNumbers) property)
* @see no
*/
public get showNumber(): boolean {
return this.getPropertyValue("showNumber");
}
public set showNumber(val: boolean) {
this.setPropertyValue("showNumber", val);
this.notifySurveyVisibilityChanged();
}
/**
* Obsolete. Use the [`showNumber`](https://surveyjs.io/form-library/documentation/api-reference/question#showNumber) property instead.
* @deprecated
*/
public get hideNumber(): boolean {
return this.getPropertyValue("hideNumber");
return !this.showNumber;
}
public set hideNumber(val: boolean) {
this.setPropertyValue("hideNumber", val);
this.notifySurveyVisibilityChanged();
this.showNumber = !val;
}
/**
* Returns `true` if the question can display its title to the left of the input field.
Expand Down Expand Up @@ -1526,15 +1536,15 @@ export class Question extends SurveyElement<Question>
*
* When the question number, title, or the entire question is invisible, this property returns an empty string.
* @see SurveyModel.questionStartIndex
* @see hideNumber
* @see showNumber
* @see titleLocation
* @see visibleIf
*/
public get no(): string {
return this.getPropertyValue("no");
}
private calcNo(): string {
if (!this.hasTitle || this.hideNumber) return "";
if (!this.hasTitle || !this.showNumber) return "";
const parentIndex: number | undefined = (<any>this.parent)?.visibleIndex;
var no = Helpers.getNumberByIndex(this.visibleIndex, this.getStartIndex(), parentIndex);
if (!!this.survey) {
Expand Down Expand Up @@ -2526,7 +2536,7 @@ export class Question extends SurveyElement<Question>
if (
!this.isVisible ||
(!this.hasTitle && !settings.numbering.includeQuestionsWithHiddenTitle) ||
(this.hideNumber && !settings.numbering.includeQuestionsWithHiddenNumber)
(!this.showNumber && !settings.numbering.includeQuestionsWithHiddenNumber)
) {
val = -1;
}
Expand Down Expand Up @@ -2923,8 +2933,9 @@ Serializer.addClass("question", [
choices: ["default", "underInput", "underTitle"],
},
{
name: "hideNumber:boolean",
name: "showNumber:boolean",
dependsOn: "titleLocation",
default: true,
visibleIf: function (obj: any) {
if (!obj) {
return true;
Expand All @@ -2946,6 +2957,7 @@ Serializer.addClass("question", [
);
},
},
{ name: "hideNumber:boolean", visible: false, isSerializable: false },
{ name: "valueName", onSettingValue: (obj: any, val: any): any => { return makeNameValid(val); } },
"enableIf:condition",
"resetValueIf:condition",
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/question_html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Serializer.addClass(
"html",
[
{ name: "html:html", serializationProperty: "locHtml" },
{ name: "hideNumber", visible: false },
{ name: "showNumber", visible: false },
{ name: "state", visible: false },
{ name: "titleLocation", visible: false },
{ name: "descriptionLocation", visible: false },
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 @@ -353,7 +353,7 @@ export var settings = {
* Nested properties:
*
* - `includeQuestionsWithHiddenNumber`: `boolean`\
* Specifies whether to number questions whose [`hideNumber`](https://surveyjs.io/form-library/documentation/api-reference/question#hideNumber) property is enabled. Default value: `false`.
* Specifies whether to number questions whose [`showNumber`](https://surveyjs.io/form-library/documentation/api-reference/question#showNumber) property is disabled. Default value: `false`.
*
* - `includeQuestionsWithHiddenTitle`: `boolean`\
* Specifies whether to number questions whose [`titleLocation`](https://surveyjs.io/form-library/documentation/api-reference/question#titleLocation) property is set to `"hidden"`. Default value: `false`.
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2869,7 +2869,7 @@ export class SurveyModel extends SurveyElementCore
*
* [View Demo](https://surveyjs.io/form-library/examples/how-to-number-pages-and-questions/ (linkStyle))
*
* If you want to hide the number of an individual question, enable its [`hideNumber`](https://surveyjs.io/form-library/documentation/api-reference/question#hideNumber) property.
* If you want to hide the number of an individual question, disable its [`showNumber`](https://surveyjs.io/form-library/documentation/api-reference/question#showNumber) property.
* @see onGetQuestionNumber
*/
public get showQuestionNumbers(): string | boolean {
Expand Down
23 changes: 6 additions & 17 deletions packages/survey-core/tests/jsonobjecttests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2586,23 +2586,12 @@ QUnit.test("itemvalue enableIf property visibility test", function (assert) {
"We show enableIf for all other properties"
);
});
QUnit.test("Change default value for question.hideNumber", function (assert) {
assert.equal(
new Question("q1").hideNumber,
false,
"By default hideNumber returns false"
);
Serializer.findProperty("question", "hideNumber").defaultValue = true;
assert.equal(
new Question("q1").hideNumber,
true,
"We have override hide number"
);
Serializer.findProperty("question", "hideNumber").defaultValue = undefined;
assert.equal(
new Question("q1").hideNumber,
false,
"We made hideNumber false by default again"
QUnit.test("Change default value for question.showNumber", function (assert) {
assert.equal(new Question("q1").showNumber, true, "By default showNumber returns true");
Serializer.findProperty("question", "showNumber").defaultValue = false;
assert.equal(new Question("q1").showNumber, false, "We have override showNumber");
Serializer.findProperty("question", "showNumber").defaultValue = true;
assert.equal(new Question("q1").showNumber, true, "We made showNumber true by default again"
);
});
QUnit.test("Serializer.getProperty()", function (assert) {
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/tests/surveyquestiontests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7636,7 +7636,7 @@ QUnit.test("Test", function (assert) {

QUnit.test("QuestionHtmlModel hide some properties", function (assert) {
let html = new QuestionHtmlModel("q1");
["hideNumber", "state", "titleLocation", "descriptionLocation", "errorLocation", "indent", "width"].forEach(property => {
["showNumber", "state", "titleLocation", "descriptionLocation", "errorLocation", "indent", "width"].forEach(property => {
assert.equal(Serializer.findProperty("html", property).visible, false, property + " should be hidden");
});
});
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 @@ -13415,7 +13415,7 @@ QUnit.test(
});
var panel = <PanelModel>survey.getPanelByName("p1");
var question = survey.getQuestionByName("q1");
var property = Serializer.findProperty("question", "hideNumber");
var property = Serializer.findProperty("question", "showNumber");

assert.ok(property.visibleIf(question), "Visible by default");

Expand Down

0 comments on commit 71634db

Please sign in to comment.