Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: [Ranking] Option to override default placeholder text #7463

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ng-template [component]="{ name: getItemValueComponentName(item), data: getItemValueComponentData(item, index, true) }"></ng-template>
</ng-container>

<div *ngIf="model.unRankingChoices.length === 0" [class]="model.cssClasses.containerPlaceholder">{{model.selectToRankEmptyRankedAreaText}}</div>
<div *ngIf="model.unRankingChoices.length === 0" [class]="model.cssClasses.containerPlaceholder" [model]="$any(model).locSelectToRankEmptyRankedAreaText" sv-ng-string></div>
</div>

<div [class]="model.cssClasses.containersDivider"></div>
Expand All @@ -20,6 +20,6 @@
<ng-template [component]="{ name: getItemValueComponentName(item), data: getItemValueComponentData(item, index) }"></ng-template>
</ng-container>

<div *ngIf="model.rankingChoices.length === 0" [class]="model.cssClasses.containerPlaceholder">{{model.selectToRankEmptyUnrankedAreaText}}</div>
<div *ngIf="model.rankingChoices.length === 0" [class]="model.cssClasses.containerPlaceholder" [model]="$any(model).locSelectToRankEmptyUnrankedAreaText" sv-ng-string></div>
</div>
</div>
4 changes: 2 additions & 2 deletions packages/survey-vue3-ui/src/Ranking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
v-if="question.unRankingChoices.length === 0"
:class="question.cssClasses.containerPlaceholder"
>
{{ question.selectToRankEmptyRankedAreaText }}
<survey-string :locString="question.locSelectToRankEmptyRankedAreaText"></survey-string>
</div>
</div>

Expand All @@ -50,7 +50,7 @@
v-if="question.rankingChoices.length === 0"
:class="question.cssClasses.containerPlaceholder"
>
{{ question.selectToRankEmptyUnrankedAreaText }}
<survey-string :locString="question.locSelectToRankEmptyUnrankedAreaText"></survey-string>
</div>
</div>
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/knockout/templates/question-ranking.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
<!-- /ko -->
<!-- /ko -->
<!-- ko if: question.unRankingChoices.length === 0 -->
<div data-bind="css: cssClasses.containerPlaceholder, text: question.selectToRankEmptyRankedAreaText"></div>
<div data-bind="css: cssClasses.containerPlaceholder">
<!-- ko template: { name: 'survey-string', data: question.locSelectToRankEmptyRankedAreaText } -->
<!-- /ko -->
</div>
<!-- /ko -->
</div>
<div data-bind="css: cssClasses.containersDivider"></div>
Expand All @@ -26,7 +29,10 @@
<!-- /ko -->
<!-- /ko -->
<!-- ko if: question.rankingChoices.length === 0 -->
<div data-bind="css: cssClasses.containerPlaceholder, text: question.selectToRankEmptyUnrankedAreaText"></div>
<div data-bind="css: cssClasses.containerPlaceholder">
<!-- ko template: { name: 'survey-string', data: question.locSelectToRankEmptyUnrankedAreaText } -->
<!-- /ko -->
</div>
<!-- /ko -->
</div>
</div>
Expand Down
18 changes: 18 additions & 0 deletions src/question_ranking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,24 @@ Serializer.addClass(
visible: true,
isSerializable: true,
},
{
name: "selectToRankEmptyRankedAreaText:text",
serializationProperty: "locSelectToRankEmptyRankedAreaText",
category: "general",
dependsOn: "selectToRankEnabled",
visibleIf: (obj: any) => {
return !!obj.selectToRankEnabled;
},
},
{
name: "selectToRankEmptyUnrankedAreaText:text",
serializationProperty: "locSelectToRankEmptyUnrankedAreaText",
category: "general",
dependsOn: "selectToRankEnabled",
visibleIf: (obj: any) => {
return !!obj.selectToRankEnabled;
},
},
{
name: "maxSelectedChoices:number",
visible: true,
Expand Down
4 changes: 2 additions & 2 deletions src/react/reactquestion_ranking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export class SurveyQuestionRanking extends SurveyQuestionElementBase {
>
<div className={this.question.getContainerClasses("from")} data-ranking="from-container">
{this.getItems(this.question.unRankingChoices, unrankedItem)}
{this.question.unRankingChoices.length === 0 ? <div className={this.question.cssClasses.containerPlaceholder}> {this.question.selectToRankEmptyRankedAreaText} </div> : null}
{this.question.unRankingChoices.length === 0 ? <div className={this.question.cssClasses.containerPlaceholder}> {this.renderLocString(this.question.locSelectToRankEmptyRankedAreaText)} </div> : null}
</div>

<div className={this.question.cssClasses.containersDivider}></div>

<div className={this.question.getContainerClasses("to")} data-ranking="to-container">
{this.getItems()}
{this.question.rankingChoices.length === 0 ? <div className={this.question.cssClasses.containerPlaceholder}>{this.question.selectToRankEmptyUnrankedAreaText}</div> : null}
{this.question.rankingChoices.length === 0 ? <div className={this.question.cssClasses.containerPlaceholder}> {this.renderLocString(this.question.locSelectToRankEmptyUnrankedAreaText)} </div> : null}
</div>
</div>
);
Expand Down
7 changes: 5 additions & 2 deletions src/vue/ranking/ranking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
:cssClasses="question.cssClasses" :question="question" :item="item" :unrankedItem=true></survey-ranking-item>

<div v-if="question.unRankingChoices.length === 0" :class="question.cssClasses.containerPlaceholder">
{{ question.selectToRankEmptyRankedAreaText }} </div>
<survey-string :locString="question.locSelectToRankEmptyRankedAreaText"></survey-string>
</div>
</div>

<div v-if="question.selectToRankEnabled" :class="question.cssClasses.containersDivider"></div>
Expand All @@ -21,7 +22,9 @@
:class="question.getItemClass(item)" :text="item.locText" :index="index" :indexText="getNumberByIndex(index)"
:cssClasses="question.cssClasses" :question="question" :item="item"></survey-ranking-item>

<div v-if="question.rankingChoices.length === 0" :class="question.cssClasses.containerPlaceholder">{{ question.selectToRankEmptyUnrankedAreaText }}</div>
<div v-if="question.rankingChoices.length === 0" :class="question.cssClasses.containerPlaceholder">
<survey-string :locString="question.locSelectToRankEmptyUnrankedAreaText"></survey-string>
</div>
</div>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
<div class="sv-ranking__containers-divider">
</div>
<div class="sv-ranking__container sv-ranking__container--empty sv-ranking__container--to" data-ranking="to-container">
<div class="sv-ranking__container-placeholder">Drag and drop choices here to rank them</div>
<div class="sv-ranking__container-placeholder">
<span class="sv-string-viewer">Drag and drop choices here to rank them</span>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
<div class="sv-ranking__containers-divider">
</div>
<div class="sv-ranking__container sv-ranking__container--empty sv-ranking__container--to" data-ranking="to-container">
<div class="sv-ranking__container-placeholder">Drag and drop choices here to rank them</div>
<div class="sv-ranking__container-placeholder">
<span class="sv-string-viewer">Drag and drop choices here to rank them</span>
</div>
</div>
</div>
33 changes: 33 additions & 0 deletions tests/question_ranking_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,37 @@ QUnit.test("Ranking: renderedSelectToRankAreasLayout", function (assert) {
assert.equal(questionModel.selectToRankAreasLayout, "horizontal", "default");
assert.equal(questionModel.renderedSelectToRankAreasLayout, "vertical", "'vertical' always on mobile");
});

QUnit.test("Ranking: check SelectToRankEmptyRankedAreaText & SelectToRankEmptyUnrankedAreaText properties", (assert) => {
let json: any = {
questions: [
{
"type": "ranking",
"name": "question1",
"selectToRankEmptyRankedAreaText": "empty ranked",
"selectToRankEmptyUnrankedAreaText": "empty unranked",
"choices": [
"Item 1",
"Item 2",
"Item 3"
]
}
],
};
let survey = new SurveyModel(json);
let question = <QuestionRankingModel>survey.getAllQuestions()[0];

const rankedProp = Serializer.getProperty("ranking", "selectToRankEmptyRankedAreaText");
const unrankedProp = Serializer.getProperty("ranking", "selectToRankEmptyUnrankedAreaText");

assert.equal(rankedProp.isVisible("", question), false);
assert.equal(unrankedProp.isVisible("", question), false);

question.selectToRankEnabled = true;
assert.equal(rankedProp.isVisible("", question), true);
assert.equal(unrankedProp.isVisible("", question), true);

assert.equal(question.selectToRankEmptyRankedAreaText, "empty ranked");
assert.equal(question.selectToRankEmptyUnrankedAreaText, "empty unranked");
});
// EO selectToRankEnabled