Skip to content

Commit c33448b

Browse files
committed
MC-3723: Advanced properties saving when invalid value is specified
- add validation to margin and padding base form - validate-number, and is between 0-999
1 parent 5606a85 commit c33448b

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

app/code/Magento/PageBuilder/view/adminhtml/ui_component/pagebuilder_base_form.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@
198198
<settings>
199199
<label translate="true">Margins and Padding</label>
200200
<placeholder translate="true">Default</placeholder>
201+
<validation>
202+
<rule name="validate-number" xsi:type="boolean">true</rule>
203+
<rule name="less-than-equals-to" xsi:type="number">999</rule>
204+
<rule name="greater-than-equals-to" xsi:type="number">0</rule>
205+
</validation>
201206
</settings>
202207
</field>
203208
</fieldset>

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/validator-rules-mixin.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ define([
4646

4747
return function (validator) {
4848
var requiredInputRule = validator.getRule('required-entry');
49+
var validateNumberRule = validator.getRule('validate-number');
50+
var lessThanEqualsToRule = validator.getRule('less-than-equals-to');
51+
var greaterThanEqualsToRule = validator.getRule('greater-than-equals-to');
4952

5053
validator.addRule(
5154
'required-entry-location-name',
@@ -115,6 +118,66 @@ define([
115118
$.mage.__(requiredInputRule.message)
116119
);
117120

121+
validator.addRule(
122+
'validate-number',
123+
function (value) {
124+
var allNumbers = true;
125+
126+
if (typeof value !== 'object') {
127+
return validateNumberRule.handler(value);
128+
}
129+
130+
_.flatten(_.map(value, _.values)).forEach(function(val) {
131+
if (!validateNumberRule.handler(val)) {
132+
return allNumbers = false;
133+
}
134+
});
135+
136+
return allNumbers;
137+
},
138+
$.mage.__(validateNumberRule.message)
139+
);
140+
141+
validator.addRule(
142+
'less-than-equals-to',
143+
function (value, params) {
144+
var allNumbers = true;
145+
146+
if (typeof value !== 'object') {
147+
return lessThanEqualsToRule.handler(value);
148+
}
149+
150+
_.flatten(_.map(value, _.values)).forEach(function(val) {
151+
if (!lessThanEqualsToRule.handler(val, params)) {
152+
return allNumbers = false;
153+
}
154+
});
155+
156+
return allNumbers;
157+
},
158+
$.mage.__(lessThanEqualsToRule.message)
159+
);
160+
161+
validator.addRule(
162+
'greater-than-equals-to',
163+
function (value, params) {
164+
var allNumbers = true;
165+
166+
if (typeof value !== 'object') {
167+
return greaterThanEqualsToRule.handler(value);
168+
}
169+
170+
_.flatten(_.map(value, _.values)).forEach(function(val) {
171+
if (!greaterThanEqualsToRule.handler(val, params)) {
172+
return allNumbers = false;
173+
}
174+
});
175+
176+
return allNumbers;
177+
},
178+
$.mage.__(greaterThanEqualsToRule.message)
179+
);
180+
118181
return validator;
119182
};
120183
});

0 commit comments

Comments
 (0)