Skip to content

Commit

Permalink
fix(admin-ui): Fix error on creating product with empty option values
Browse files Browse the repository at this point in the history
Fixes #141
  • Loading branch information
michaelbromley committed Aug 20, 2019
1 parent fd68d1e commit 452f5a9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#textArea
(keyup)="handleKey($event)"
(focus)="isFocussed = true"
(blur)="isFocussed = false"
(blur)="handleBlur()"
[(ngModel)]="input"
[disabled]="disabled"
></textarea>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ export class OptionValueInputComponent implements ControlValueAccessor {
switch (event.key) {
case ',':
case 'Enter':
this.options = unique([...this.options, ...this.parseInputIntoOptions(this.input)]);
this.input = '';
this.onChangeFn(this.options);
this.addOptionValue();
event.preventDefault();
break;
case 'Backspace':
Expand All @@ -85,6 +83,17 @@ export class OptionValueInputComponent implements ControlValueAccessor {
}
}

handleBlur() {
this.isFocussed = false;
this.addOptionValue();
}

private addOptionValue() {
this.options = unique([...this.options, ...this.parseInputIntoOptions(this.input)]);
this.input = '';
this.onChangeFn(this.options);
}

private parseInputIntoOptions(input: string): string[] {
return input
.split(/[,\n]/)
Expand Down
3 changes: 2 additions & 1 deletion admin-ui/src/app/catalog/providers/product-detail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class ProductDetailService {
) {
const createProduct$ = this.dataService.product.createProduct(input);

const createOptionGroups$ = createVariantsConfig.groups.length
const nonEmptyOptionGroups = createVariantsConfig.groups.filter(g => 0 < g.values.length);
const createOptionGroups$ = nonEmptyOptionGroups.length
? forkJoin(
createVariantsConfig.groups.map(c => {
return this.dataService.product.createProductOptionGroups({
Expand Down

0 comments on commit 452f5a9

Please sign in to comment.