Skip to content

Commit

Permalink
MAGETWO-39178: Create "getStyles" data-binding
Browse files Browse the repository at this point in the history
- Localize usage of additinalClasses property
  • Loading branch information
Denys Rul committed Jun 26, 2015
1 parent 076732e commit 3696279
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ protected function getStreetFieldConfig($attributeCode, array $attributeConfig,
'dataScope' => $lineIndex,
'provider' => $providerName,
'validation' => $isFirstLine ? ['required-entry' => true] : [],
'additionalClasses' => $isFirstLine ? : 'additional'
'additionalClasses' => [
'additional' => $isFirstLine
]
];
}
return [
Expand All @@ -221,7 +223,9 @@ protected function getStreetFieldConfig($attributeCode, array $attributeConfig,
'type' => 'group',
'config' => [
'template' => 'ui/group/group',
'additionalClasses' => 'street'
'additionalClasses' => [
'street' => true
]
],
'children' => $streetLines,
];
Expand Down
23 changes: 21 additions & 2 deletions app/code/Magento/Ui/view/base/web/js/form/components/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@ define([
template: 'ui/group/group',
fieldTemplate: 'ui/form/field',
breakLine: true,
validateWholeGroup: false
validateWholeGroup: false,
additionalClasses: {}
},

/**
* Extends this with defaults and config.
* Then calls initObservable, iniListenes and extractData methods.
*/
initialize: function () {
return this._super();
this._super()
._setClasses();

return this;
},

/**
Expand All @@ -40,6 +44,21 @@ define([
return this;
},

/**
* Extends 'additionalClasses' object.
*
* @returns {Group} Chainable.
*/
_setClasses: function () {
_.extend(this.additionalClasses, {
required: this.required,
_error: this.error,
_disabled: this.disabled
});

return this;
},

/**
* Defines if group has only one element.
* @return {Boolean}
Expand Down
18 changes: 18 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/form/element/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ define([
error: '',
notice: '',
customScope: '',
additionalClasses: {},

listens: {
value: 'onUpdate',
Expand All @@ -47,6 +48,8 @@ define([
_.bindAll(this, 'reset');

this._super();
._setClasses();

this.initialValue = this.getInitialValue();

this.value(this.initialValue);
Expand Down Expand Up @@ -91,6 +94,21 @@ define([
return this;
},

/**
* Extends 'additionalClasses' object.
*
* @returns {Abstract} Chainable.
*/
_setClasses: function () {
_.extend(this.additionalClasses, {
required: this.required,
_error: this.error,
_disabled: this.disabled
});

return this;
},

/**
* Gets initial value of element
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/
-->
<div class="field" data-bind="visible: visible, attr: {'name': element.dataScope}, css: getStyles()">
<div class="field" data-bind="visible: visible, attr: {'name': element.dataScope}, css: additionalClasses">

<label class="label" data-bind="attr: { for: element.uid }">
<!-- ko if: element.label -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/
-->
<div class="field" data-bind="css: element.additionalClass, css: getStyles()">
<div class="field" data-bind="css: additionalClasses">
<label class="label">
<span data-bind="text: element.label"></span>
</label>
Expand Down

0 comments on commit 3696279

Please sign in to comment.