Skip to content

Commit

Permalink
fix(admin-ui): Use select control for string custom field with options
Browse files Browse the repository at this point in the history
Fixes #546
  • Loading branch information
michaelbromley committed Nov 10, 2020
1 parent e189bd4 commit 5c59b67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ViewContainerRef,
} from '@angular/core';
import { ControlValueAccessor, FormArray, FormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import { StringCustomFieldConfig } from '@vendure/common/lib/generated-types';
import { ConfigArgType, CustomFieldType, DefaultFormComponentId } from '@vendure/common/lib/shared-types';
import { assertNever } from '@vendure/common/lib/shared-utils';
import { simpleDeepClone } from '@vendure/common/lib/simple-deep-clone';
Expand Down Expand Up @@ -289,12 +290,16 @@ export class DynamicFormInputComponent
const type = argDef?.type as ConfigArgType | CustomFieldType;
switch (type) {
case 'string':
case 'localeString':
if (this.isConfigArgDef(argDef) && argDef.ui?.options) {
case 'localeString': {
const hasOptions =
!!(this.isConfigArgDef(argDef) && argDef.ui?.options) ||
!!(argDef as StringCustomFieldConfig).options;
if (hasOptions) {
return { component: 'select-form-input' };
} else {
return { component: 'text-form-input' };
}
}
case 'int':
case 'float':
return { component: 'number-form-input' };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<select clrSelect [formControl]="formControl" [vdrDisabled]="readonly">
<option *ngFor="let option of config.options" [value]="option.value">
{{ option.label || option.value }}
{{ (option | customFieldLabel) || option.label || option.value }}
</option>
</select>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select {
width: 100%;
}

0 comments on commit 5c59b67

Please sign in to comment.