Start with one option

This commit is contained in:
shamoon 2024-07-06 15:12:11 -07:00
parent 29a142dee4
commit e39c3b22fb
4 changed files with 10 additions and 9 deletions

View File

@ -3460,14 +3460,14 @@
<source>Create new custom field</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts</context>
<context context-type="linenumber">52</context>
<context context-type="linenumber">53</context>
</context-group>
</trans-unit>
<trans-unit id="8751213029607178010" datatype="html">
<source>Edit custom field</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts</context>
<context context-type="linenumber">56</context>
<context context-type="linenumber">57</context>
</context-group>
</trans-unit>
<trans-unit id="6672809941092516947" datatype="html">

View File

@ -16,7 +16,7 @@
<div [formGroup]="objectForm.controls.extra_data">
@switch (objectForm.get('data_type').value) {
@case (CustomFieldDataType.Select) {
<button type="button" class="btn btn-sm btn-primary mb-2" (click)="addSelectOption()">
<button type="button" class="btn btn-sm btn-primary my-2" (click)="addSelectOption()">
<span i18n>Add option</span>&nbsp;<i-bs name="plus-circle"></i-bs>
</button>
<div formArrayName="select_options">

View File

@ -86,10 +86,6 @@ describe('CustomFieldEditDialogComponent', () => {
component.dialogMode = EditDialogMode.CREATE
fixture.detectChanges()
component.ngOnInit()
expect(
component.objectForm.get('extra_data').get('select_options').value.length
).toBe(0)
component.addSelectOption()
expect(
component.objectForm.get('extra_data').get('select_options').value.length
).toBe(1)
@ -97,9 +93,13 @@ describe('CustomFieldEditDialogComponent', () => {
expect(
component.objectForm.get('extra_data').get('select_options').value.length
).toBe(2)
component.addSelectOption()
expect(
component.objectForm.get('extra_data').get('select_options').value.length
).toBe(3)
component.removeSelectOption(0)
expect(
component.objectForm.get('extra_data').get('select_options').value.length
).toBe(1)
).toBe(2)
})
})

View File

@ -42,6 +42,7 @@ export class CustomFieldEditDialogComponent
this.objectForm.get('data_type').disable()
}
if (this.object?.data_type === CustomFieldDataType.Select) {
this.selectOptions.clear()
this.object.extra_data.select_options.forEach((option) =>
this.selectOptions.push(new FormControl(option))
)
@ -61,7 +62,7 @@ export class CustomFieldEditDialogComponent
name: new FormControl(null),
data_type: new FormControl(null),
extra_data: new FormGroup({
select_options: new FormArray([]),
select_options: new FormArray([new FormControl(null)]),
}),
})
}