2

I would like to add below class on "Firstname"

class="validate-length minimum-length-10 maximum-length-100"

It should be applied on Checkout Page.

domain.com/checkout/

Need to override file magento\vendor\magento\module-checkout\view\frontend\templates\onepage.phtml?

asked Dec 7, 2016 at 1:45
4
  • Have you got answer of this question? Commented Dec 7, 2016 at 7:03
  • No @Rakesh. I think magento.stackexchange.com/questions/148951/… Can apply class here Right ? Commented Dec 7, 2016 at 7:04
  • Yes so i have think you have did for checkout, may be try with same method for above case. Commented Dec 7, 2016 at 7:08
  • Yes @Rakesh It's Gonna Work :) Commented Dec 7, 2016 at 7:09

1 Answer 1

1

You can add that validation using overriding \Magento\Checkout\Block\Checkout\LayoutProcessor using plugin.

etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
 <plugin name="custom_field" type="Vendor\Module\Plugin\Checkout\Model\Checkout\LayoutProcessor" sortOrder="100"/>
</type>

LayoutProcessor.php

<?php
namespace Vendor\Module\Plugin\Checkout\Model\Checkout\LayoutProcessor;
class LayoutProcessor
{
/**
 * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
 * @param array $jsLayout
 * @return array
 */
public function afterProcess(
 \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
 array $jsLayout
) {
 /*$jsLayout you can set your field that you want to customize*/
 $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
 ['shippingAddress']['children']['shipping-address-fieldset']['children']['postcode'] = [
 'component' => 'Magento_Ui/js/form/element/abstract',
 'config' => [
 'customScope' => 'shippingAddress',
 'template' => 'ui/form/field',
 'elementTmpl' => 'ui/form/element/input',
 'options' => [],
 ],
 'dataScope' => 'shippingAddress.postcode',
 'label' => 'Zip/Postal Code',
 'provider' => 'checkoutProvider',
 'visible' => true,
 'validation' => ['required-entry' => true], //Here you can add you validation
 ];
 return $jsLayout;
 }
}
shreyas d
2701 silver badge14 bronze badges
answered Dec 7, 2016 at 7:47
2
  • Hi @Chirag. I already posted that link in comments Commented Dec 7, 2016 at 8:17
  • can you pass class name or ID so i can add css is that possible Commented Oct 25, 2019 at 12:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.