OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions Change Address validation

This topic contains 18 replies, has 7 voices, and was last updated by  Bhavesh Tailor 7 years, 3 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #33945

    cardiac
    Participant

    Hi all,

    I wanted to change the OroAddressBundle validation of the Address entity.

    In the OroAddressBundle you have:

    But I want to remove these validations. I don’t want the fields to be validated!

    I had read this article, but didn’t helped me though.

    Can you help me with this? Is there a possibility to remove/overwrite the validation?

    PS: It’s ok for me if I just overwrite/remove the validation of Oro\Bundle\AddressBundle\Entity\Address and pre fill the country field.

    Regards

Viewing 15 replies - 1 through 15 (of 18 total)
  • Author
    Replies
  • #33946

    Yevhen Shyshkin
    Participant

    Hello, cardiac.

    There are several ways to do that:

    1) you can create custom validation group (like described in article) and use it during validation – this is the most flexible solution;

    2) if you are working with forms you can disable validation on specific fields by setting validaton_groups option to false e.g. via form extension;

    3) the most tricky way is to customize Symfony validation itself or its configuration (see building of validation configuration) and fix validation there.

    P.S. When you working with validation you should remember that by default validation can’t be overridden – it simply adds new constraints without removing of old ones.

    #33947

    cardiac
    Participant

    Hello Yevhen,

    thanks for your reply.

    I don’t get what is happening in the article.

    Can you give me an example how to remove the checks for “NotBlank”? In OroAddress without creating a new entity?

    I am sorry that I don’t understand what to do in 1)

    #33948

    ignat
    Participant

    Hi cardiac,

    As an option please follow next steps to override validation of existing entity:

    1) Locate validation rules of entity in existing bundles. For your case it will be this file https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/AddressBundle/Resources/config/validation.yml (use appropriate version, current link is for master branch)

    2) In your bundle add yours Resources/config/validation.yml and copy validation rules from original source.

    3) Add some unique validation group to your validation rules in Resources/config/validation.yml and comment out rules that you want to ignore. I guess in your case your file would look like this: https://gist.github.com/ignat-s/09170db64544ed9a95b2.

    4) Add form extension for form type of your entity and inject custom validation group.

    For more information please check this webinar that includes topic of overriding of validation using this approach: https://youtu.be/GNNU0veNmks?t=1775

    For reference you could use this repository and branch: https://github.com/orocrm/training-crm-application/tree/webinar/customize.

    You would be able to find where form extension injects custom validation group here: https://github.com/orocrm/training-crm-application/blob/webinar/customize/src/Webinar/Bundle/AccountBundle/Form/Extension/AddB2bCustomer.php#L38

    And you would be able to find where validation is overridden here: https://github.com/orocrm/training-crm-application/blob/webinar/customize/src/Webinar/Bundle/AccountBundle/Resources/config/validation.yml#L11

    Thanks,
    Ignat

    #33949

    cardiac
    Participant

    Thank you ignat!
    I will follow your tutorial soon and give feedback

    #33950

    Good Morning,

    I have problems at point
    4) Add extension form for form type of entity and inject your custom validation group.
    I don’t know where to start.
    Could you help me a little.

    Thank you

    #33951

    Yevhen Shyshkin
    Participant

    Hello.

    You should use Symfony form extension and alter validation group of the required form. Please, check the links – they contain both explanations and examples.

    #33952

    Hello.

    These changes the forms of entity OROCRM own validations are made but these result in des access the REST API?

    Thanks

    #33953

    Yevhen Shyshkin
    Participant

    Hello.

    In fact right now REST API works via forms too (e.g. https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/UserBundle/Resources/config/form.yml#L208), so you can customize it in the same way.

    In future we are going to remove API dependency on forms, but for now you can use the same approach as for forms.

    #33954

    hello_world
    Participant

    Hi guys, i’ve stuck with another problem after extending a form. I removed NotBlank validation constraint from Lead’s last name, but can’t save new entity in database due to a sql error:

    Could you tell me please what is the best way to deal with this error?
    Also, after i removed this constraint the asterisk sign (*) near input is still present.

    #33955

    Yevhen Shyshkin
    Participant

    Look’s like you removed only form validation constraint, but this field also have NOT NULL restriction at DB table. If you want to remove it too – you have to write a migration in your bundle and change this property (make it nullable).

    #33956

    hello_world
    Participant

    Ok, thanks for the response, Yevhen.

    #33957

    mandraque
    Participant

    Hello,

    I have problems with OroAddressBundle, I was able to change validations OroCRM\Bundle\ContactBundle\Entity\ContactAddress , but I can’t remove validations required from widget

    please help me

    #33958

    Yevhen Shyshkin
    Participant

    Hello, mandraque.

    You can’t disable existing validation – you should use different validation group instead.

    #33959

    Bhavesh Tailor
    Participant

    Hello , Yevhen

    I did remove b2b customer field from opportunity thats why into my table orocrm_sales_opportunity customer_id is null. While i trying to edit status,probability etc. then i got error “This value should not be blank.” . While i remove beflow contain from OroCRM/Bundle/SalesBundle/Resources/config/validation.yml
    customer:
    – Valid: ~
    – NotBlank: ~

    Then I am able to update fields . How can i override this validation.yml for inline edit datagrid

    Thank You


    Bhavesh

    #33960

    Bhavesh Tailor
    Participant

    Hi ,

    Can you suggest me how to remove customer validation constraint from inline-edit datagrid . i am trying to resolve but getting error :

    {“code”:400,”message”:”Validation Failed”,”errors”:{“errors”:[“This value should not be blank.”],”children”
    :{“status”:[],”owner”:[]}}}

    This error getting because of null value for b2bcustomer into orocrm_sales_opportunity table and inside validation.yml

    customer:
    – Valid: ~
    – NotBlank: ~

    Please suggest how to disable validation for inline edit datagrid ..

    Thank You in advance

    Bhavesh


    Bhavesh

Viewing 15 replies - 1 through 15 (of 18 total)

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top