From 379578171982a28c26c25eb190b9a36801862cc4 Mon Sep 17 00:00:00 2001 From: AFS Date: Sun, 8 Nov 2015 13:30:12 +0100 Subject: [PATCH 1/4] Remote emptyMsg Set emptyMsg from remote to allow for custom error/info message. --- js/dependent-dropdown.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/dependent-dropdown.js b/js/dependent-dropdown.js index e1624ce..a544c9f 100644 --- a/js/dependent-dropdown.js +++ b/js/dependent-dropdown.js @@ -120,6 +120,9 @@ }, success: function (data) { selected = isEmpty(data.selected) ? (self.initVal === false ? null : self.initVal): data.selected; + if (!isEmpty(data.emptyMsg)) { + vNullMsg = data.emptyMsg; + } if (isEmpty(data)) { addOption($el, '', vNullMsg, ''); } @@ -220,4 +223,4 @@ $(function () { $('select.depdrop').depdrop(); }); -}(window.jQuery)); \ No newline at end of file +}(window.jQuery)); From 722438e9fc0d920de2d620d885e19ddcd89bf96a Mon Sep 17 00:00:00 2001 From: Andre Schuurman Date: Mon, 9 Nov 2015 14:37:16 +0100 Subject: [PATCH 2/4] If no data, data.output or no records in data.output show vNullMsg. Fix to show vNullMsg in Select2 widgets by setting value for message to 0. Remove obsolete condition when data is available. --- js/dependent-dropdown.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/js/dependent-dropdown.js b/js/dependent-dropdown.js index a544c9f..d84503b 100644 --- a/js/dependent-dropdown.js +++ b/js/dependent-dropdown.js @@ -123,20 +123,19 @@ if (!isEmpty(data.emptyMsg)) { vNullMsg = data.emptyMsg; } - if (isEmpty(data)) { - addOption($el, '', vNullMsg, ''); + if (isEmpty(data) || isEmpty(data.output) || Object.keys(data.output).length == 0) { + $el.html(''); + addOption($el, 0, vNullMsg, ''); } else { $el.html(self.getSelect(data.output, vDefault, selected)); if ($el.find('optgroup').length > 0) { $el.find('option[value=""]').attr('disabled', 'disabled'); } - if (data.output) { - if (selected && $.isArray(selected) && $el.attr('multiple')) { - $el.val(selected); - } - $el.removeAttr('disabled'); + if (selected && $.isArray(selected) && $el.attr('multiple')) { + $el.val(selected); } + $el.removeAttr('disabled'); } optCount = $el.find('option').length; if ($el.find('option[value=""]').length > 0) { From 7499796c016fd7e0af94c2b82fcf10e2e3c1cf65 Mon Sep 17 00:00:00 2001 From: AFS Date: Mon, 9 Nov 2015 14:49:54 +0100 Subject: [PATCH 3/4] Custom emptyMsg Instructions added on how to use custom emptyMsg --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a32bd8..e6349e9 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,12 @@ View the [plugin documentation](http://plugins.krajee.com/dependent-dropdown) an ``` {group-name: {id: , name: }} ``` + + When no data is available for a specific situation (like error), you can send a custom emptyMsg + + ``` + {emptyMsg: ''} + ``` ## Installation @@ -350,4 +356,4 @@ $('#input-id').depdrop('init'); ## License -**dependent-dropdown** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details. \ No newline at end of file +**dependent-dropdown** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details. From 59a55120a978746f04af685629e5a01e88b86e80 Mon Sep 17 00:00:00 2001 From: AFS Date: Mon, 9 Nov 2015 14:51:13 +0100 Subject: [PATCH 4/4] text update Make more clear what emptyMsg can be used for. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6349e9..4c398a2 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ View the [plugin documentation](http://plugins.krajee.com/dependent-dropdown) an {group-name: {id: , name: }} ``` - When no data is available for a specific situation (like error), you can send a custom emptyMsg + When no data is available for a specific situation (like an backend error), you can send a custom emptyMsg ``` {emptyMsg: ''}