Search code examples
prestashopprestashop-1.7

How to remove validation lastname from prestashop 1.7.8.3 backoffice


I have a question how to remove validation from LastName inside client address edit. I need to allow numbers inside this field.

I found here thread Prestashop : Remove Lastname Field Rules Validation From B.O, but this solution is not working.


Solution

  • Finally, I have caught the issue. You are editing in admin panel and I was sharing code for front end. Please try below steps for admin:

    Step 1 - file classes/Address.php

    'lastname' => ['type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 255],
    

    Change this to isAnything

    Step 2 - src\PrestaShopBundle\Form\Admin\Sell\Address/CustomerAddressType.php

    Change your code to below code:

    line 209: add('last_name', TextType::class, [
            'label' => $this->trans('Last name', 'Admin.Global'),
            'help' => $genericInvalidCharsMessage,
            'required' => true,
            'constraints' => [
                new NotBlank([
                    'message' => $this->trans(
                        'This field cannot be empty.', 'Admin.Notifications.Error'
                    ),
                ]),
                new CleanHtml(),
                new TypedRegex([
                    'type' => TypedRegex::TYPE_GENERIC_NAME,
                ]),
                new Length([
                    'max' => AddressConstraint::MAX_LAST_NAME_LENGTH,
                    'maxMessage' => $this->trans(
                        'This field cannot be longer than %limit% characters',
                        'Admin.Notifications.Error',
                        ['%limit%' => AddressConstraint::MAX_LAST_NAME_LENGTH]
                    ),
                ]),
            ],
        ])
    

    Now, you are ready to go and check.