0

I have created confirm password field in adminhtml edit.php file . For confirm password functionality, how to include java script in adminhtml edit form ? Or other method to check confirm password in custom Module befor save the form ?

| improve this question | | | | |
  • you have to create requirejs-config.js file and define your js inside it. – Rakesh Jesadiya Feb 17 '17 at 10:19
-1

to validate the password that it matches the entered password add validate-cpassword class to your validate password fiels. This is defined in lib/web/prototype/validation.js file so you may take a look if you want.

 $fieldset->addField(
            'password',
            'password',
            [
               'name' => 'password',
               'label' => __('New Password'),
               'title' => __('New Password'),
               'class' => 'validate-admin-password admin__control-text'
            ]
        );

        $fieldset->addField(
           'confirmation',
           'password',
            [
               'name' => 'password_confirmation',
               'label' => __('Password Confirmation'),
               'class' => 'validate-cpassword admin__control-text'
           ]
      );

These line from magento core may help you

| improve this answer | | | | |
4

You can set Custom.js file in your Layout file xyz.xml only set head

<head>
    <script src="Test_Demo::js/custom.js"/>
</head>

also define this file name in view/adminhtml/requirejs-config.js

var config = {
    map: {
        '*': {
            custom:'Test_Demo/js/custom'
        }
    }
};

=>finaly edit.php in use

<script type="text/javascript">
require(["jquery",custom], function ($) {
     alert(123);
});

=>Its working..
| improve this answer | | | | |
2

Yes, You may include JS in admin form in following way:

Create requirejs-config.js inside your module Path:

Vendor/Module/view/adminhtml/requirejs-config.js

var config = {
    map: {
        '*': {
            'jsalias':'Vendor_Module/js/jsalias'
        }
    }
};

Create JS inside your module's adminhtml part

Path:Vendor/Module/view/adminhtml/web/js/jsalias.js

Not it's time to include js inside your form.

$field = $fieldset->addField('password', 'password', array(
    'label' => 'password',
    'name' => 'password',
    'required' => true,
    'class' => 'required-entry input-text',
));
$field->setAfterElementHtml('<script>
//<![CDATA[

   require(["jquery","jsalias"], function ($) {
       alert('Yes.. It works..!!!');   
   });

//]]>
</script>');
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.