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.
- CreatorTopic
- September 21, 2015 at 3:05 am #33945
Hi all,
I wanted to change the OroAddressBundle validation of the Address entity.
In the OroAddressBundle you have:
12345678910country:- NotBlank: ~street:- NotBlank: ~city:- NotBlank: ~postalCode:- NotBlank: ~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
- CreatorTopic
- AuthorReplies
- September 22, 2015 at 1:58 am #33946
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.
September 22, 2015 at 2:48 am #33947Hello 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)
September 25, 2015 at 5:29 pm #33948Hi 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,
IgnatOctober 2, 2015 at 4:06 am #33949Thank you ignat!
I will follow your tutorial soon and give feedbackFebruary 2, 2016 at 12:51 am #33950Good 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
February 2, 2016 at 1:26 am #33951Hello.
You should use Symfony form extension and alter validation group of the required form. Please, check the links – they contain both explanations and examples.
February 3, 2016 at 2:41 am #33952Hello.
These changes the forms of entity OROCRM own validations are made but these result in des access the REST API?
Thanks
February 3, 2016 at 3:37 am #33953Hello.
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.
March 24, 2016 at 3:04 am #33954Hi 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:
12SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "last_name" violates not-null constraintDETAIL: Failing row contains (1, demand_generation, null, null, null, 1, null, 1, new, null, null, 1, sdfdsf, null, sdfsdfdfdsfds, null, null, null, null, null, null, null, null, null, null, 2016-03-24 09:58:08, null, null, null, null, null, null, null, null)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.March 24, 2016 at 3:40 am #33955Look’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).
March 24, 2016 at 4:54 am #33956Ok, thanks for the response, Yevhen.
August 13, 2016 at 11:54 am #33957Hello,
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
August 16, 2016 at 1:48 am #33958Hello, mandraque.
You can’t disable existing validation – you should use different validation group instead.
January 3, 2017 at 6:18 am #33959Hello , 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
January 3, 2017 at 10:54 pm #33960Hi ,
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
- AuthorReplies
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.