From 1dfa6c3bdf061e1b3824ef137a03c500c3a0ad48 Mon Sep 17 00:00:00 2001 From: ulion Date: Wed, 11 Mar 2015 08:30:34 +0800 Subject: [PATCH 1/2] Enhance the select field with null value support --- .../decorators/bootstrap/select.html | 21 ++++++++++++++++++- src/services/schema-form.js | 15 +++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/directives/decorators/bootstrap/select.html b/src/directives/decorators/bootstrap/select.html index 05c45a5ae..c7bd41c32 100644 --- a/src/directives/decorators/bootstrap/select.html +++ b/src/directives/decorators/bootstrap/select.html @@ -1,4 +1,4 @@ -
+
+ + +
+
\ No newline at end of file diff --git a/src/services/schema-form.js b/src/services/schema-form.js index b1664f0e2..99774b04c 100644 --- a/src/services/schema-form.js +++ b/src/services/schema-form.js @@ -359,6 +359,21 @@ angular.module('schemaForm').provider('schemaForm', } } + if (obj.type === 'select' && obj.titleMap && obj.allowAutoNullOption !== false) { + // when allowNull === false, we leave titleMap as it is. + // else we filter out the null value and setup allowNull to the label + // so the select template will behaviour different according to it. + obj.titleMap = obj.titleMap.filter(function(item) { + if (item.value === null) { + // so we have null value option, setup the label and make it always selectable. + if (obj.allowAutoNullOption === undefined) + obj.allowAutoNullOption = item.name === null ? '' : item.name; + return false; + } + return true; + }); + } + // Are we inheriting readonly? if (readonly === true) { // Inheriting false is not cool. obj.readonly = true; From 34c9c29fb56cdd98f891b35fa000e4e3c6841d0f Mon Sep 17 00:00:00 2001 From: ulion Date: Sat, 21 Mar 2015 06:42:55 +0800 Subject: [PATCH 2/2] Do not change titleMap order if null value in it. --- src/services/schema-form.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/services/schema-form.js b/src/services/schema-form.js index 99774b04c..c2b52bfaa 100644 --- a/src/services/schema-form.js +++ b/src/services/schema-form.js @@ -359,18 +359,16 @@ angular.module('schemaForm').provider('schemaForm', } } - if (obj.type === 'select' && obj.titleMap && obj.allowAutoNullOption !== false) { - // when allowNull === false, we leave titleMap as it is. - // else we filter out the null value and setup allowNull to the label - // so the select template will behaviour different according to it. - obj.titleMap = obj.titleMap.filter(function(item) { + if (obj.type === 'select' && obj.titleMap) { + // we check whether null value is in titleMap. if so, we fix possible null + // label and set allowAutoNullOption to false, then leave the titleMap as it is + obj.titleMap.forEach(function(item) { if (item.value === null) { - // so we have null value option, setup the label and make it always selectable. if (obj.allowAutoNullOption === undefined) - obj.allowAutoNullOption = item.name === null ? '' : item.name; - return false; + obj.allowAutoNullOption = false; + if (item.name === null) + item.name = ''; } - return true; }); }