I Want To Set Minimum Length Value For Street Address Field On Admin Side
I want to set min_text_length = 5 For Street Address Field In Customer Address Form
I am Trying To Update Attribute but Not Working
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
if (version_compare($context->getVersion(), '1.0.1', '<')) {
$customerSetup = $this->customerSetup->create(['setup' => $setup]);
$customerSetup->addAttribute(
'customer_address',
'street',
[
'type' => 'static',
'label' => 'Street Address',
'input' => 'multiline',
'backend' => \Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend::class,
'sort_order' => 70,
'multiline_count' => 4,
'validate_rules' => '{"max_text_length":255,"min_text_length":5}',
'position' => 70,
]
);
}
}
In Database Already Set {"max_text_length":255,"min_text_length":5} But Validation not Working
Note :- Admin Side Not Frontend Side.
-
you can update attribute and add validation by setup script(can add manually from DB),For front checkout remove validation by changing LayoutProcessor.php and do same thing in register and update address section by removing validation classKetan Borada– Ketan Borada2019年06月19日 06:56:33 +00:00Commented Jun 19, 2019 at 6:56
-
i know about address form and checkout page but in admin side not find any reference or solutionRonak Rathod– Ronak Rathod2019年06月19日 07:00:40 +00:00Commented Jun 19, 2019 at 7:00
-
What is your magento version?Sohel Rana– Sohel Rana2019年06月19日 07:03:05 +00:00Commented Jun 19, 2019 at 7:03
-
v 2.2.8 @Sohel RanaRonak Rathod– Ronak Rathod2019年06月19日 07:03:29 +00:00Commented Jun 19, 2019 at 7:03
-
Please post your code/ mention clearly which form you want to customize in question.Vivek Kumar– Vivek Kumar2019年06月19日 07:11:37 +00:00Commented Jun 19, 2019 at 7:11
4 Answers 4
You Can do it by Script and update validation within it.You have to change
'validate_rules' => '{"max_text_length":255,"min_text_length":5}',
You can change it directly from DB you have to do it carefully.
- Open table
eav_attributeand findattribute_codestreet and getattribute_idfrom it (generally attribute_id is 28).
- Open table
customer_eav_attributeand find thatattribute_id(28 in my case). update invalidate_rulescolumn{"max_text_length":255,"min_text_length":5}
Now it is done in admin
Note: You have to remove if it occurs in front
-
let me check and replay soonRonak Rathod– Ronak Rathod2019年06月19日 07:35:24 +00:00Commented Jun 19, 2019 at 7:35
-
no bro its not working i have already try to update attributeRonak Rathod– Ronak Rathod2019年06月19日 07:40:11 +00:00Commented Jun 19, 2019 at 7:40
-
but in data base already set {"max_text_length":255,"min_text_length":5} but validation is not workingRonak Rathod– Ronak Rathod2019年06月19日 07:40:53 +00:00Commented Jun 19, 2019 at 7:40
-
1+ for responseRonak Rathod– Ronak Rathod2019年06月19日 07:49:12 +00:00Commented Jun 19, 2019 at 7:49
-
may any other extension conflicts or js error,otherwise you can check it working for meKetan Borada– Ketan Borada2019年06月19日 08:39:37 +00:00Commented Jun 19, 2019 at 8:39
i am not sure if this works
<rule name="required-entry" xsi:type="boolean">true</rule>
Example from first name
<field name="city" formElement="input">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">address</item>
</item>
</argument>
<settings>
remove this validation
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
</validation>
up to here
<dataType>text</dataType>
</settings>
</field>
-
its not workingRonak Rathod– Ronak Rathod2019年06月17日 05:56:25 +00:00Commented Jun 17, 2019 at 5:56
-
@RkRathod hi sorry i thought you wanted to remove the validation. i will let you know if i find something. sorry againjibin george– jibin george2019年06月17日 07:25:57 +00:00Commented Jun 17, 2019 at 7:25
-
@RkRathod try this : <item name="max_text_length" xsi:type="number">5</item>jibin george– jibin george2019年06月17日 07:34:32 +00:00Commented Jun 17, 2019 at 7:34
-
@RkRathod did it work? or was it something new you foundjibin george– jibin george2019年06月17日 08:05:04 +00:00Commented Jun 17, 2019 at 8:05
-
@RkRathod if you dont mind will you share the answer?jibin george– jibin george2019年06月17日 08:39:44 +00:00Commented Jun 17, 2019 at 8:39
update column validate_rules = {"min_text_length":"1","max_text_length":"10","input_validation":"length"} in table customer_eav_attribute with attribute_id = 28. it's working for me for first fied in address enter image description here
Step 2: In ui_component/customer_address_form.xml enter image description here
Step 3: Create Observer enter image description here
Step 4: override file Magento\Customer\Model\Address\DataProvider.php enter image description here
-
because the first validate rules updated in db is worked for the first street view only, and not worked for 2 last street view, so the idea is create 2 new dummy fields and hide 2 last street fields. then when we save the 2 new dummy field, we will set 2 last street fields by that 2 dummy field.fudu– fudu2021年10月01日 07:19:39 +00:00Commented Oct 1, 2021 at 7:19
You can do this from the admin (Magento 2.3.3):
-
1Where can i find this in admin?Nayem323– Nayem3232020年02月05日 05:35:53 +00:00Commented Feb 5, 2020 at 5:35
-
@Nayem Stores -> Attributes -> Customer Address, and select "Street Address" from the list.Niels– Niels2020年02月06日 08:04:03 +00:00Commented Feb 6, 2020 at 8:04
-
It looks like Adobe have removed access to editing customer attributes from 2.4.x Community/Open Source edition. Adobe Commerce only :( docs.magento.com/user-guide/stores/attributes-customer.htmlAMc– AMc2022年01月21日 09:41:52 +00:00Commented Jan 21, 2022 at 9:41
Explore related questions
See similar questions with these tags.