From 5bc035baacce13267e49588db18a27d1ace72d23 Mon Sep 17 00:00:00 2001 From: Bart-art Date: Fri, 23 Jun 2017 09:47:58 +0200 Subject: [PATCH 1/4] Allow option disabling for optgroup binding The optgroup Knockout binding formats its options before usage in the optionsAfterRender of the form/element/select.html knockout template. In this process all extra data of the options will be stripped and the optionsAfterRenderer cannot access the disabled value of any option. Because of this the delimiter option in the country_id select in checkout is choosable by the customer. --- .../Ui/view/base/web/js/lib/knockout/bindings/optgroup.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js index 1a90a46d60db6..ef82dd6e5a7a3 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js @@ -297,10 +297,15 @@ define([ ko.utils.arrayForEach(options, function (option) { var value = applyToObject(option, optionsValue, option), label = applyToObject(option, optionsText, value) || '', + disabled = applyToObject(option, 'disabled', false) || false, obj = {}, space = '\u2007\u2007\u2007'; obj[optionTitle] = applyToObject(option, optionsText + 'title', value); + + if(disabled) { + obj['disabled'] = disabled; + } label = label.replace(nbspRe, '').trim(); From 48de2860bec16981ec4f1e6fbbba78ced0ae60a1 Mon Sep 17 00:00:00 2001 From: Bart-art Date: Fri, 23 Jun 2017 11:20:02 +0200 Subject: [PATCH 2/4] Adjusted format to safisfy coding standard --- .../Ui/view/base/web/js/lib/knockout/bindings/optgroup.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js index ef82dd6e5a7a3..6a2bc031c331c 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js @@ -302,9 +302,8 @@ define([ space = '\u2007\u2007\u2007'; obj[optionTitle] = applyToObject(option, optionsText + 'title', value); - - if(disabled) { - obj['disabled'] = disabled; + if (disabled) { + obj.disabled = disabled; } label = label.replace(nbspRe, '').trim(); From 3db94422ca601810a6621e63b4afc099d841f81f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niklas=20Bartholom=C3=A4us?= Date: Fri, 23 Jun 2017 12:16:54 +0200 Subject: [PATCH 3/4] added missing newline --- .../Ui/view/base/web/js/lib/knockout/bindings/optgroup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js index 6a2bc031c331c..bf9e8ebe6eaa1 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js @@ -302,6 +302,7 @@ define([ space = '\u2007\u2007\u2007'; obj[optionTitle] = applyToObject(option, optionsText + 'title', value); + if (disabled) { obj.disabled = disabled; } From 3620da4207cc46f58f6de700be61e47433041352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Niklas=20Bartholom=C3=A4us?= Date: Fri, 23 Jun 2017 14:37:36 +0200 Subject: [PATCH 4/4] Removed github editor auto indendtion --- .../Ui/view/base/web/js/lib/knockout/bindings/optgroup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js index bf9e8ebe6eaa1..2925c5859eddd 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/optgroup.js @@ -302,7 +302,7 @@ define([ space = '\u2007\u2007\u2007'; obj[optionTitle] = applyToObject(option, optionsText + 'title', value); - + if (disabled) { obj.disabled = disabled; }