Skip to content

Commit cd09c7c

Browse files
author
Stanislav Idolov
authored
ENGCOM-2748: Refactor JS code and added JS component file #17527
2 parents f965dcd + 01ed836 commit cd09c7c

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/form.phtml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
<input name="form_key" type="hidden" value="<?= $block->escapeHtml($block->getFormKey()) ?>" />
2222
<?= $block->getChildHtml('form') ?>
2323
</form>
24-
25-
26-
<script>
27-
require(['jquery', "mage/mage"], function(jQuery){
28-
29-
jQuery('#edit_form').mage('form').mage('validation', {validationUrl: '<?= /* @escapeNotVerified */ $block->getValidationUrl() ?>'});
30-
31-
});
24+
<script type="text/x-magento-init">
25+
{
26+
"#edit_form": {
27+
"Magento_Catalog/catalog/product/edit/attribute": {
28+
"validationUrl": "<?= /* @escapeNotVerified */ $block->getValidationUrl() ?>"
29+
}
30+
}
31+
}
3232
</script>
3333
<?= /* @escapeNotVerified */ $block->getFormScripts() ?>

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/action/attribute.phtml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
<form action="<?= /* @escapeNotVerified */ $block->getSaveUrl() ?>" method="post" id="attributes-edit-form" class="attributes-edit-form" enctype="multipart/form-data">
1212
<?= $block->getBlockHtml('formkey') ?>
1313
</form>
14-
<script>
15-
require(['jquery', "mage/mage"], function(jQuery){
16-
17-
jQuery('#attributes-edit-form').mage('form')
18-
.mage('validation', {validationUrl: '<?= /* @escapeNotVerified */ $block->getValidationUrl() ?>'});
19-
20-
});
14+
<script type="text/x-magento-init">
15+
{
16+
"#attributes-edit-form": {
17+
"Magento_Catalog/catalog/product/edit/attribute": {
18+
"validationUrl": "<?= /* @escapeNotVerified */ $block->getValidationUrl() ?>"
19+
}
20+
}
21+
}
2122
</script>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'mage/mage'
9+
], function ($) {
10+
'use strict';
11+
12+
return function (config, element) {
13+
14+
$(element).mage('form').mage('validation', {
15+
validationUrl: config.validationUrl
16+
});
17+
};
18+
});

0 commit comments

Comments
 (0)