Skip to content

Commit

Permalink
Merge pull request #276 from romanblanco/bz1559159
Browse files Browse the repository at this point in the history
Setting the default_value for TagControl dialog field
  • Loading branch information
karelhala authored Apr 4, 2018
2 parents facd4db + c7ab976 commit e9a7280
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/dialog-user/components/dialog-user/dialogField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export class DialogFieldController extends DialogFieldClass {
this.dialogField = this.field;
this.validation = null;
this.patternflyVersion = this.$window.patternflyVersion || 3;
if (this.dialogField.type === 'DialogFieldTagControl') {
this.setDefaultValue();
}
}

/**
Expand Down Expand Up @@ -95,6 +98,21 @@ export class DialogFieldController extends DialogFieldClass {
public refreshSingleField() {
this.singleRefresh({ field: this.field.name });
}

/**
* This method is setting the default_value for a tag control's select box.
* In case the default_value is not set for the ng-model of the component,
* an empty value option is displayed
* @memberof DialogFieldController
* @function setDefaultValue
*/
private setDefaultValue() {
let defaultOption = _.find(this.dialogField.values, { id: null })
if (defaultOption) {
defaultOption.id = 0;
this.dialogField.default_value = defaultOption.id
}
}
}

export default class DialogField {
Expand Down

0 comments on commit e9a7280

Please sign in to comment.