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

Do not show clear button in dropdown in Creator V1 fix #7118 #7119

Merged
merged 1 commit into from
Oct 11, 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 @@ -32,7 +32,7 @@
(change)="inputChange($event)" (blur)="blur($event)" (focus)="focus($event)"/>
</div>
<div *ngIf="(model.allowClear && model.cssClasses.cleanButtonIconId)"
[class]="model.cssClasses.cleanButton" (click)="clear($event)" [visible]="!model.isEmpty()">
[class]="model.cssClasses.cleanButton" (click)="clear($event)" [visible]="model.showClearButton">
<!-- ko component: { name: 'sv-svg-icon', params: { css: model.cssClasses.cleanButtonSvg, iconName: model.cssClasses.cleanButtonIconId, size: 'auto' } } -->
<!-- /ko -->
<svg [iconName]="model.cssClasses.cleanButtonIconId" [partCss]="model.cssClasses.cleanButtonSvg" [title]="model.clearCaption"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ng-template [component]="{ name: 'sv-tagbox-filter', data: { model: dropdownModel, question: model } }"></ng-template>
</div>
<div *ngIf="(model.allowClear && model.cssClasses.cleanButtonIconId)" [class]="model.cssClasses.cleanButton"
(click)="clear($event)" [visible]="!model.isEmpty()">
(click)="clear($event)" [visible]="model.showClearButton">
<!-- ko component: { name: 'sv-svg-icon', params: { css: model.cssClasses.cleanButtonSvg, iconName: model.cssClasses.cleanButtonIconId, size: 'auto' } } -->
<!-- /ko -->
<svg [iconName]="model.cssClasses.cleanButtonIconId" [partCss]="model.cssClasses.cleanButtonSvg" [title]="model.clearCaption"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<div
:class="question.cssClasses.cleanButton"
v-if="question.allowClear && question.cssClasses.cleanButtonIconId"
v-show="!question.isEmpty()"
v-show="question.showClearButton"
@click="clear"
>
<sv-svg-icon
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-vue3-ui/src/components/tagbox/Tagbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<div
:class="question.cssClasses.cleanButton"
v-if="question.allowClear && question.cssClasses.cleanButtonIconId"
v-show="!question.isEmpty()"
v-show="question.showClearButton"
@click="clear"
>
<sv-svg-icon
Expand Down
2 changes: 1 addition & 1 deletion src/knockout/components/dropdown/dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
event: { blur: blur, focus: focus }"></input>
</div>
<!-- ko if: (question.allowClear && question.cssClasses.cleanButtonIconId) -->
<div data-bind="css: question.cssClasses.cleanButton, click: clear, visible: !question.isEmpty() ">
<div data-bind="css: question.cssClasses.cleanButton, click: clear, visible: question.showClearButton ">
<!-- ko component: { name: 'sv-svg-icon', params: { css: question.cssClasses.cleanButtonSvg, iconName: question.cssClasses.cleanButtonIconId, size: 'auto', title: question.clearCaption } } -->
<!-- /ko -->
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/knockout/components/tagbox/tagbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>
</div>
<!-- ko if: (question.allowClear && question.cssClasses.cleanButtonIconId) -->
<div data-bind="css: question.cssClasses.cleanButton, click: clear, visible: !question.isEmpty() ">
<div data-bind="css: question.cssClasses.cleanButton, click: clear, visible: question.showClearButton ">
<!-- ko component: { name: 'sv-svg-icon', params: { css: question.cssClasses.cleanButtonSvg, iconName: question.cssClasses.cleanButtonIconId, size: 'auto', title: question.clearCaption } } -->
<!-- /ko -->
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/question_dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export class QuestionDropdownModel extends QuestionSelectBase {
public set showOptionsCaption(val: boolean) {
this.allowClear = val;
}
public get showClearButton(): boolean {
return this.allowClear && !this.isEmpty() && (!this.isDesignMode || settings.supportCreatorV2);
}
public get optionsCaption() {
return this.placeholder;
}
Expand Down
4 changes: 3 additions & 1 deletion src/question_tagbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ export class QuestionTagboxModel extends QuestionCheckboxModel {
super.clearValue();
this.dropdownListModel.clear();
}

public get showClearButton(): boolean {
return this.allowClear && !this.isEmpty() && (!this.isDesignMode || settings.supportCreatorV2);
}
//a11y
public get isNewA11yStructure(): boolean {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/react/dropdown-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class SurveyQuestionDropdownBase<T extends Question> extends SurveyQuesti
createClearButton(): JSX.Element | null {
if (!this.question.allowClear || !this.question.cssClasses.cleanButtonIconId) return null;

const style = { display: this.question.isEmpty() ? "none" : "" };
const style = { display: !this.question.showClearButton ? "none" : "" };
return (
<div
className={this.question.cssClasses.cleanButton}
Expand Down
2 changes: 1 addition & 1 deletion src/vue/components/dropdown/dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<div
:class="question.cssClasses.cleanButton"
v-if="question.allowClear && question.cssClasses.cleanButtonIconId"
v-show="!question.isEmpty()"
v-show="question.showClearButton"
@click="clear"
>
<sv-svg-icon
Expand Down
2 changes: 1 addition & 1 deletion src/vue/components/tagbox/tagbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<div
:class="question.cssClasses.cleanButton"
v-if="question.allowClear && question.cssClasses.cleanButtonIconId"
v-show="!question.isEmpty()"
v-show="question.showClearButton"
@click="clear"
>
<sv-svg-icon
Expand Down
29 changes: 29 additions & 0 deletions tests/questionDropdownTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,35 @@ QUnit.test("deserialize showOptionsCaption & optionsCaption to placeholder & all
});
});

QUnit.test("question.showClearButton", assert => {
const json = {
questions: [
{
"type": "dropdown",
"name": "q1",
"optionsCaption": "New optionsCaption",
"choices": [
"Ford",
"Vauxhall",
"Volkswagen"
]
}]
};
const survey = new SurveyModel(json);
const q = <QuestionDropdownModel>survey.getQuestionByName("q1");
assert.equal(q.showClearButton, false, "question is empty");
q.value = "Ford";
assert.equal(q.showClearButton, true, "question is not empty");
q.allowClear = false;
assert.equal(q.showClearButton, false, "allowClear is false");
q.allowClear = true;
survey.setDesignMode(true);
assert.equal(q.showClearButton, false, "design mode");
settings.supportCreatorV2 = true;
assert.equal(q.showClearButton, true, "Creator V2");
settings.supportCreatorV2 = false;
});

QUnit.test("ListModel localization", assert => {
const json = {
questions: [
Expand Down
30 changes: 29 additions & 1 deletion tests/question_tagbox_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,4 +1291,32 @@ QUnit.test("TagBox readOnlyText property should be reactive, Bug#6830", (assert)
survey.locale = "";
assert.equal(q.readOnlyText, "en-sel", "Empty en, #3");
assert.equal(q.dropdownListModel.filterStringPlaceholder, "en-sel", "dropdownlist en, #3");
});
});
QUnit.test("question.showClearButton", assert => {
const json = {
questions: [
{
"type": "tagbox",
"name": "q1",
"optionsCaption": "New optionsCaption",
"choices": [
"Ford",
"Vauxhall",
"Volkswagen"
]
}]
};
const survey = new SurveyModel(json);
const q = <QuestionTagboxModel>survey.getQuestionByName("q1");
assert.equal(q.showClearButton, false, "question is empty");
q.value = "Ford";
assert.equal(q.showClearButton, true, "question is not empty");
q.allowClear = false;
assert.equal(q.showClearButton, false, "allowClear is false");
q.allowClear = true;
survey.setDesignMode(true);
assert.equal(q.showClearButton, false, "design mode");
settings.supportCreatorV2 = true;
assert.equal(q.showClearButton, true, "Creator V2");
settings.supportCreatorV2 = false;
});