From 218f732dc207ca6b979064e3d8107cf39e896365 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 3 Dec 2014 16:07:46 -0800 Subject: [PATCH] [Forms] Add CompositeController Add a controller for composite controls; this is used to flag contained controls as required when they have been partially filled in (to treat entering one of two such fields as invalid.) WTD-593. --- platform/forms/bundle.json | 4 +++ .../res/templates/controls/composite.html | 28 ++++++++++--------- .../src/controllers/CompositeController.js | 27 ++++++++++++++++++ 3 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 platform/forms/src/controllers/CompositeController.js diff --git a/platform/forms/bundle.json b/platform/forms/bundle.json index 2954a8eeea..5654d80f2b 100644 --- a/platform/forms/bundle.json +++ b/platform/forms/bundle.json @@ -40,6 +40,10 @@ "key": "DateTimeController", "implementation": "controllers/DateTimeController.js", "depends": [ "$scope" ] + }, + { + "key": "CompositeController", + "implementation": "controllers/CompositeController.js" } ], "templates": [ diff --git a/platform/forms/res/templates/controls/composite.html b/platform/forms/res/templates/controls/composite.html index 7b1585a48a..f6a4d9f46a 100644 --- a/platform/forms/res/templates/controls/composite.html +++ b/platform/forms/res/templates/controls/composite.html @@ -1,13 +1,15 @@ - - - - - {{item.name}} - - \ No newline at end of file + + + + + + {{item.name}} + + + \ No newline at end of file diff --git a/platform/forms/src/controllers/CompositeController.js b/platform/forms/src/controllers/CompositeController.js new file mode 100644 index 0000000000..2e91118fb5 --- /dev/null +++ b/platform/forms/src/controllers/CompositeController.js @@ -0,0 +1,27 @@ +/*global define*/ + +define( + [], + function () { + "use strict"; + + function CompositeController() { + function isDefined(element) { + return typeof element !== 'undefined'; + } + + function or(a, b) { + return a || b; + } + + return { + isNonEmpty: function (value) { + return (value || []).map(isDefined).reduce(or, false); + } + }; + } + + return CompositeController; + + } +); \ No newline at end of file