Skip to content

Commit 2d937c9

Browse files
authored
Add other-option when configuring a survey (#1128)
* Add other-option when configuring a survey * Removing other-option from dropdown * Removing forgotten mistake
1 parent 79d4820 commit 2d937c9

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

apps/web-mzima-client/src/app/settings/surveys/create-field-modal/create-field-modal.component.html

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@
4040
</div>
4141

4242
<!-- Has options -->
43-
<div class="form-row" *ngIf="hasOptions">
43+
<div class="form-row form-row__options" *ngIf="hasOptions">
4444
<div class="form-head-panel">
4545
<mat-label class="form-label" [data-qa]="'field-options'"
4646
>{{ 'form.field_options' | translate }}
4747
</mat-label>
4848

4949
<mzima-client-button
5050
fill="outline"
51-
color="secondary"
51+
color="gray"
52+
size="medium"
53+
class="form-row__options__button"
5254
(buttonClick)="addOption()"
5355
[data-qa]="'btn-add-option'"
5456
>
@@ -65,16 +67,15 @@
6567
(input)="onChange(i)"
6668
placeholder="{{ 'form.field_name_placeholder' | translate }}"
6769
[data-qa]="'option-' + i"
70+
[disabled]="option.value === 'Other'"
6871
/>
69-
7072
<mzima-client-button
7173
matSuffix
7274
fill="clear"
7375
color="danger"
7476
[iconOnly]="true"
7577
class="button-flat button-beta"
7678
(buttonClick)="removeOption(i)"
77-
*ngIf="selectedFieldType.options.length > 1"
7879
[data-qa]="'btn-remove-option-' + i"
7980
>
8081
<mat-icon icon svgIcon="delete"></mat-icon>
@@ -84,6 +85,26 @@
8485
{{ option.error | translate }}
8586
</mat-error>
8687
</div>
88+
<div
89+
*ngIf="
90+
selectedFieldType?.options?.length > 0 &&
91+
!selectedFieldType?.options?.includes('Other') &&
92+
selectedFieldType.input !== 'select'
93+
"
94+
>
95+
<mzima-client-button
96+
fill="outline"
97+
color="gray"
98+
size="medium"
99+
class="form-row__options__button"
100+
(buttonClick)="addOther()"
101+
>
102+
{{ 'form.field_add_other' | translate }}
103+
</mzima-client-button>
104+
<p class="form-row__options__add-other">
105+
{{ 'form.field_add_other_desc' | translate }}
106+
</p>
107+
</div>
87108
</div>
88109

89110
<div class="form-row" *ngIf="selectedFieldType.input === 'tags'">

apps/web-mzima-client/src/app/settings/surveys/create-field-modal/create-field-modal.component.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,35 @@ quill-editor {
8181
&__item {
8282
margin-bottom: 8px;
8383
}
84+
&__options {
85+
background-color: var(--color-neutral-10);
86+
padding: 16px;
87+
border-radius: 4px;
88+
.form-label {
89+
font-weight: 700;
90+
}
91+
&__button {
92+
&::ng-deep {
93+
.mzima-button {
94+
background-color: transparent;
95+
font-size: 14px;
96+
min-height: 22px;
97+
width: unset;
98+
}
99+
}
100+
}
101+
.form-row__item {
102+
background-color: var(--color-light);
103+
.mat-input-element {
104+
padding: 12px;
105+
}
106+
}
107+
&__add-other {
108+
padding: 6px;
109+
font-size: 12px;
110+
color: var(--color-neutral-70);
111+
}
112+
}
84113

85114
.form-head-panel {
86115
margin-bottom: 8px;

apps/web-mzima-client/src/app/settings/surveys/create-field-modal/create-field-modal.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ export class CreateFieldModalComponent implements OnInit {
259259
this.fieldOptions.push({ value: '', error: '' });
260260
}
261261

262+
public addOther() {
263+
if (!this.selectedFieldType.options) this.selectedFieldType.options = [];
264+
if (this.selectedFieldType.options.includes('Other')) return;
265+
this.selectedFieldType.options.push('Other');
266+
this.fieldOptions.push({ value: 'Other', error: '' });
267+
}
268+
262269
private setTempSelectedFieldType() {
263270
this.fieldOptions = this.selectedFieldType.options.map((opt: string) => ({
264271
value: opt,

apps/web-mzima-client/src/assets/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@
245245
"edit_post_type": "Edit Survey: {{form}}",
246246
"edit_post_types": "Edit Surveys",
247247
"field_add_option": "Add",
248+
"field_add_other": "Add other",
249+
"field_add_other_desc": "Allows entering a custom option that is not listed among the provided choices.",
248250
"field_default": "Field Default",
249251
"field_key": "Field Key",
250252
"field_type": "Field Type",

0 commit comments

Comments
 (0)