Skip to content

Commit 54469ce

Browse files
committed
magento:magento2 Missed form validation in Admin Order Address Edit route sales/order/address
1 parent f710f9b commit 54469ce

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractForm.php

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ protected function _addAttributesToForm($attributes, \Magento\Framework\Data\For
176176
[
177177
'name' => $attribute->getAttributeCode(),
178178
'label' => __($attribute->getStoreLabel()),
179-
'class' => $attribute->getFrontendClass(),
180-
'required' => $attribute->isRequired()
179+
'class' => $this->getValidationClasses($attribute),
180+
'required' => $attribute->isRequired(),
181181
]
182182
);
183183
if ($inputType == 'multiline') {
@@ -227,4 +227,50 @@ public function getFormValues()
227227
{
228228
return [];
229229
}
230+
231+
/**
232+
* Retrieve frontend classes according validation rules
233+
*
234+
* @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute
235+
*
236+
* @return string
237+
*/
238+
private function getValidationClasses(\Magento\Customer\Api\Data\AttributeMetadataInterface $attribute) : string
239+
{
240+
$out = [];
241+
$out[] = $attribute->getFrontendClass();
242+
243+
$textLengthValidateClasses = $this->getTextLengthValidateClasses($attribute);
244+
if (!empty($textLengthValidateClasses)) {
245+
$out = array_merge($out, $textLengthValidateClasses);
246+
}
247+
248+
$out = !empty($out) ? implode(' ', array_unique(array_filter($out))) : '';
249+
return $out;
250+
}
251+
252+
/**
253+
* Retrieve validation classes by min_text_length and max_text_length rules
254+
*
255+
* @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute
256+
*
257+
* @return array
258+
*/
259+
private function getTextLengthValidateClasses(\Magento\Customer\Api\Data\AttributeMetadataInterface $attribute) : array
260+
{
261+
$classes = [];
262+
263+
$validateRules = $attribute->getValidationRules();
264+
if (!empty($validateRules['min_text_length'])) {
265+
$classes[] = 'minimum-length-' . $validateRules['min_text_length'];
266+
}
267+
if (!empty($validateRules['max_text_length'])) {
268+
$classes[] = 'maximum-length-' . $validateRules['max_text_length'];
269+
}
270+
if (!empty($classes)) {
271+
$classes[] = 'validate-length';
272+
}
273+
274+
return $classes;
275+
}
230276
}

0 commit comments

Comments
 (0)