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
Jackson
9,98933 gold badges132 silver badges217 bronze badges
-
Have you got answer of this question?Rakesh Jesadiya– Rakesh Jesadiya2016年12月07日 07:03:29 +00:00Commented Dec 7, 2016 at 7:03
-
No @Rakesh. I think magento.stackexchange.com/questions/148951/… Can apply class here Right ?Jackson– Jackson2016年12月07日 07:04:42 +00:00Commented 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.Rakesh Jesadiya– Rakesh Jesadiya2016年12月07日 07:08:19 +00:00Commented Dec 7, 2016 at 7:08
-
Yes @Rakesh It's Gonna Work :)Jackson– Jackson2016年12月07日 07:09:31 +00:00Commented Dec 7, 2016 at 7:09
1 Answer 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;
}
}
answered Dec 7, 2016 at 7:47
Chirag Prajapati
2,9522 gold badges20 silver badges44 bronze badges
-
Hi @Chirag. I already posted that link in commentsJackson– Jackson2016年12月07日 08:17:06 +00:00Commented Dec 7, 2016 at 8:17
-
can you pass class name or ID so i can add css is that possiblejibin george– jibin george2019年10月25日 12:18:36 +00:00Commented Oct 25, 2019 at 12:18
Explore related questions
See similar questions with these tags.
default