Skip to content

Commit

Permalink
Merge dd1ca9f into a037c39
Browse files Browse the repository at this point in the history
  • Loading branch information
mzazrivec committed Apr 21, 2020
2 parents a037c39 + dd1ca9f commit 06db674
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: required
dist: trusty
language: node_js
node_js:
- '8'
- '10'

npm:
- '3'
Expand Down
1 change: 0 additions & 1 deletion src/dialog-editor/components/field/field.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
</div>
<div ng-if="vm.fieldData.options.force_multi_value">
<select class="form-control" multiple miq-select
ng-init="vm.convertValuesToArray()"
ng-model="vm.fieldData.default_value">
<option ng-repeat="value in vm.fieldData.values" value="{{value[0]}}">{{value[1]}}</option>
</select>
Expand Down
24 changes: 0 additions & 24 deletions src/dialog-editor/components/field/fieldComponent.spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/dialog-editor/components/field/fieldComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ class FieldController {
this.DialogEditor.updatePositions(this.getFields(tabId, boxId));
}

/**
* Convert default value for multiple select fields to an array
* @memberof FieldController
* @function convertValuesToArray
*/
public convertValuesToArray() {
this.fieldData.default_value = angular.fromJson(this.fieldData.default_value);
}

/**
* Find fields at tabId and boxId.
* @memberof FieldController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,46 @@ class ModalFieldController {
};
}

public $onChanges(changesObj) {
if (changesObj.modalData && changesObj.modalData.default_value === []) {
this.modalData.default_value = '';
public emptyDefaultValue(field) {
// FIXME replace with DialogData shared impl?
const byDataType = field.data_type === 'integer' ? 0 : '';

switch (field.type) {
case 'DialogFieldTagControl':
return field.options.force_single_value ? byDataType : [];
case 'DialogFieldDropDownList':
return field.options.force_multi_value ? [] : byDataType;
default:
return byDataType;
}
}

public resetDefaultValue() {
// TODO first use the real value if possible
this.modalData.default_value = this.emptyDefaultValue(this.modalData);
console.log('resetDefaultValue', this.modalData.default_value);
}

// reset default_value on data_type change and single/multi change
public $onInit() {
const watch = (path, fn) => {
this.$scope.$watch(path, (current, old) => {
if (current !== old) {
return fn();
}
});
};

watch('vm.modalData.options.force_multi_value', () => this.resetDefaultValue());
watch('vm.modalData.options.force_single_value', () => this.resetDefaultValue());
watch('vm.modalData.data_type', () => this.resetDefaultValue());
// vm.modalData.values - handled by entriesChange
}

// reset default_value on entries list change
public entriesChange() {
setTimeout(() => this.$element.find('select').selectpicker('refresh'));
this.resetDefaultValue();
}
}

Expand Down

0 comments on commit 06db674

Please sign in to comment.