3

I have read this URL for equalTo validation.

I have add custom field using LayoutProcessor.php file and set validation like this :

'validation' => ['validate-no-empty' => false,'validate-password' => true,'min_text_len‌​gth' => 7, 'max_text_length' => 20,],

all above validation is working good except "equalTo".

I have try like this: , "equalTo" => "#fieldname" but still not working, can anyone help me, how can i use "equalTo" validation in LayoutProcessor.php file?

My Code:

<?php
namespace Packeg\Modulename\Plugin\Checkout\Model\Checkout;


class LayoutProcessor
{

    public function afterProcess(
        \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
        array  $jsLayout
    ) {


        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $customerSession = $objectManager->get('Magento\Customer\Model\Session');
        if(!$customerSession->isLoggedIn()) {




        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['before-shipping-method-form']['children']['password_1'] = [
            'component' => 'Magento_Ui/js/form/element/abstract',
            'config' => [
                'customScope' => 'shippingAddress',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/password',
                'id' => 'password_1'
            ],
            'dataScope' => 'shippingAddress.password_1',
            'label' => 'Create Password',
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' => ['validate-no-empty' => false,'validate-password' => true,'min_text_len‌​gth' => 7, 'max_text_length' => 20,],
            'sortOrder' => 250,
            'id' => 'password_1'
        ];

        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['before-shipping-method-form']['children']['password_2'] = [
            'component' => 'Magento_Ui/js/form/element/abstract',
            'config' => [
                'customScope' => 'shippingAddress',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/password',
                'id' => 'password_2'
            ],
            'dataScope' => 'shippingAddress.password_2',
            'label' => 'Re-enter Password',
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' => ['validate-no-empty' => true, 'validate-password2'=> true , "min_text_len‌​gth" => 7, "max_text_length" => 20],
            'sortOrder' => 255,
            'id' => 'password_2'
        ];



    }
        return $jsLayout;
    }
}
2
  • Please provide your code which you used in LayoutProcessor.php.
    – kunj
    Jul 9, 2018 at 5:39
  • i have add my code Jul 9, 2018 at 6:28

1 Answer 1

0

Try this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $customerSession = $objectManager->get('Magento\Customer\Model\Session');
        if(!$customerSession->isLoggedIn()) {


            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['before-shipping-method-form']['children']['password_1'] = [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/password',
                    'id' => 'password_1',

                ],
                'dataScope' => 'shippingAddress.password_1',
                'label' => 'Create Password',
                'provider' => 'checkoutProvider',
                'visible' => true,
                'validation' => ['validate-no-empty' => false, 'validate-password' => true, 'min_text_len‌​gth' => 7, 'max_text_length' => 20,],
                'sortOrder' => 250,
                'id' => 'password_1'
            ];

            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
            ['shippingAddress']['children']['before-shipping-method-form']['children']['password_2'] = [
                'component' => 'Magento_Ui/js/form/element/abstract',
                'config' => [
                    'customScope' => 'shippingAddress',
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/password',
                    'id' => 'password_2'
                ],
                'dataScope' => 'shippingAddress.password_2',
                'label' => 'Re-enter Password',
                'provider' => 'checkoutProvider',
                'visible' => true,
                'validation' => ['validate-no-empty' => true, 'validate-password2' => true, "min_text_len‌​gth" => 7, "max_text_length" => 20,'equalTo'=>'[name="password_1"]'],
                'sortOrder' => 255,
                'id' => 'password_2'
            ];

I have added this 'equalTo'=>'[name="password_1"]' in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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