[CORD-1539] Support for static choices and default values
Change-Id: I988b1863221a0678aff1bd151fb2d26e1a33fe92
diff --git a/src/app/core/field/field.html b/src/app/core/field/field.html
index 9baa1d5..5dad952 100644
--- a/src/app/core/field/field.html
+++ b/src/app/core/field/field.html
@@ -12,7 +12,7 @@
ng-minlength="vm.field.validators.minlength || 0"
ng-maxlength="vm.field.validators.maxlength || 2000"
ng-required="vm.field.validators.required || false" />
-<select class="form-control" ng-if ="vm.field.type === 'select'"
+<select class="form-control" ng-if="vm.field.type === 'select'"
name = "{{vm.name}}"
ng-options="item.id as item.label for item in vm.field.options"
ng-model="vm.ngModel"
diff --git a/src/app/core/field/field.ts b/src/app/core/field/field.ts
index 5c5b48a..f05a8e4 100644
--- a/src/app/core/field/field.ts
+++ b/src/app/core/field/field.ts
@@ -38,6 +38,16 @@
throw new Error('[xosField] Please provide an ng-model');
}
+ // NOTE set default value (if any)
+ if (this.field.default && !angular.isDefined(this.ngModel)) {
+ if (this.field.type === 'number') {
+ this.ngModel = parseInt(this.field.default, 10);
+ }
+ else {
+ this.ngModel = this.field.default;
+ }
+ }
+
if (this.field.type === 'array') {
this.$scope.$watch(() => this.ngModel.length, () => {