From c0f5ea343839c66f987f77774395fc428e9a9338 Mon Sep 17 00:00:00 2001 From: Aura Esteban Date: Thu, 5 Apr 2018 15:21:38 +0800 Subject: [PATCH 1/5] Add autofill --- .../directives/ModelFieldReference/ModelFieldReference.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/client/common/directives/ModelFieldReference/ModelFieldReference.js b/client/common/directives/ModelFieldReference/ModelFieldReference.js index 6360c68c..397953e3 100644 --- a/client/common/directives/ModelFieldReference/ModelFieldReference.js +++ b/client/common/directives/ModelFieldReference/ModelFieldReference.js @@ -173,6 +173,13 @@ angular.module('dashboard.directives.ModelFieldReference', [ scope.onSelect(response[scope.options.defaultIndex]); } } + if (typeof scope.options.defaultIndex === 'boolean' && scope.options.autofill) { + if (response.length > 0) { + _.forEach(response, function(item) { + scope.onSelect(item); + }); + } + } }); }; From ba46843c6bb8cec436e6c32a3225eb3590cc1516 Mon Sep 17 00:00:00 2001 From: Aura Esteban Date: Thu, 5 Apr 2018 15:31:45 +0800 Subject: [PATCH 2/5] Fix variable name --- .../directives/ModelFieldReference/ModelFieldReference.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/common/directives/ModelFieldReference/ModelFieldReference.js b/client/common/directives/ModelFieldReference/ModelFieldReference.js index 397953e3..cac88331 100644 --- a/client/common/directives/ModelFieldReference/ModelFieldReference.js +++ b/client/common/directives/ModelFieldReference/ModelFieldReference.js @@ -173,7 +173,7 @@ angular.module('dashboard.directives.ModelFieldReference', [ scope.onSelect(response[scope.options.defaultIndex]); } } - if (typeof scope.options.defaultIndex === 'boolean' && scope.options.autofill) { + if (typeof scope.options.autofill === 'boolean' && scope.options.autofill) { if (response.length > 0) { _.forEach(response, function(item) { scope.onSelect(item); From 0316e6da161e39709f533c404fe07c029c1a16e2 Mon Sep 17 00:00:00 2001 From: Aura Esteban Date: Thu, 5 Apr 2018 15:45:27 +0800 Subject: [PATCH 3/5] Remove condition --- .../directives/ModelFieldReference/ModelFieldReference.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/client/common/directives/ModelFieldReference/ModelFieldReference.js b/client/common/directives/ModelFieldReference/ModelFieldReference.js index cac88331..a823bdeb 100644 --- a/client/common/directives/ModelFieldReference/ModelFieldReference.js +++ b/client/common/directives/ModelFieldReference/ModelFieldReference.js @@ -174,11 +174,9 @@ angular.module('dashboard.directives.ModelFieldReference', [ } } if (typeof scope.options.autofill === 'boolean' && scope.options.autofill) { - if (response.length > 0) { - _.forEach(response, function(item) { - scope.onSelect(item); - }); - } + _.forEach(response, function(item) { + scope.onSelect(item); + }); } }); }; From 15a72929dc4481f4693bcb8f52abd5a73f921589 Mon Sep 17 00:00:00 2001 From: Aura Esteban Date: Thu, 5 Apr 2018 16:19:54 +0800 Subject: [PATCH 4/5] Add flag if default is set - from #303 --- .../directives/ModelFieldReference/ModelFieldReference.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/common/directives/ModelFieldReference/ModelFieldReference.js b/client/common/directives/ModelFieldReference/ModelFieldReference.js index a823bdeb..791c86b4 100644 --- a/client/common/directives/ModelFieldReference/ModelFieldReference.js +++ b/client/common/directives/ModelFieldReference/ModelFieldReference.js @@ -60,6 +60,7 @@ angular.module('dashboard.directives.ModelFieldReference', [ scope.selected.items = []; //for multi-select scope.selected.item = null; //for single select; initialize to null so placeholder is displayed scope.list = []; + scope.isDefaultSet = false; /** * Watch for scope.data. If it has no data, it will clear the selected item/s. @@ -173,10 +174,11 @@ angular.module('dashboard.directives.ModelFieldReference', [ scope.onSelect(response[scope.options.defaultIndex]); } } - if (typeof scope.options.autofill === 'boolean' && scope.options.autofill) { + if (typeof scope.options.autofill === 'boolean' && scope.options.autofill && !scope.isDefaultSet) { _.forEach(response, function(item) { scope.onSelect(item); }); + scope.isDefaultSet = true; } }); }; From aa63708cb4af9f6fb1590609361b51fe5b4985de Mon Sep 17 00:00:00 2001 From: cmandocdoc Date: Wed, 21 Mar 2018 10:11:29 +0800 Subject: [PATCH 5/5] [DD-3382] add if flag if default has bee set --- .../directives/ModelFieldReference/ModelFieldReference.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/common/directives/ModelFieldReference/ModelFieldReference.js b/client/common/directives/ModelFieldReference/ModelFieldReference.js index 791c86b4..a63234e9 100644 --- a/client/common/directives/ModelFieldReference/ModelFieldReference.js +++ b/client/common/directives/ModelFieldReference/ModelFieldReference.js @@ -168,9 +168,10 @@ angular.module('dashboard.directives.ModelFieldReference', [ scope.list.unshift(addNewItem); } - if (typeof scope.options.defaultIndex === 'number') { + if (typeof scope.options.defaultIndex === 'number' && !scope.isDefaultSet) { if (response[scope.options.defaultIndex]) { //scope.selected.items = [response[scope.options.defaultIndex]]; + scope.isDefaultSet = true; scope.onSelect(response[scope.options.defaultIndex]); } }