ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

This topic contains 8 replies, has 3 voices, and was last updated by Stepan Yudin Stepan Yudin 2 years ago.

  • Creator
    Topic
  • #13556
    Stepan Yudin
    Stepan Yudin
    Participant

    For example i have a 3 entities:
    – AbstractCar
    – Car
    – Brand

    Car extends AbstractCar, AbstractCar has validation.yml like this:

    CarsBundle\Entity\AbstractCar:
    properties:
    name:
    - NotBlank: ~

    Brand entity has field ‘cars’ that contains OneToMany relations with Car entities.
    Brand form type contains ‘cars’ field rendered as ‘oro_collection’ with ‘type’ => New AbstractCarType().
    I want the AbstractCar frontend constraints be applied to AbstractCarType form types that are rendered in BrandType form. Is it possible?

    Is it possible?


    Docker environment for Symfony2/OroCRM/OroBAP development on Windows platform
    https://github.com/stepansib/sf-oro-docker

Viewing 8 replies - 1 through 8 (of 8 total)
  • Author
    Replies
  • #13637

    Yurii Muratov
    Oro Core

    Hi, @stepan-sib.
    Does the validation work on the backend side in the described case?

    #13666
    Stepan Yudin
    Stepan Yudin
    Participant

    Hi, Yurii

    If i am not wrong – the validator checks for constraint both front-end and back-end validators.
    In my case there is a simple NotBlank constraint, that of course fires at the front-end by JS.

    In fact i need any solution to validate every embedded form in collection with constraints defined in AbstractCar’s validation.yml


    Docker environment for Symfony2/OroCRM/OroBAP development on Windows platform
    https://github.com/stepansib/sf-oro-docker

    #13853

    Yurii Muratov
    Oro Core

    Hi, @stepan-sib.

    Please look how it was done for Address collection.

    We have AddressCollectionType that extends oro_collection https://github.com/laboro/platform/blob/master/src/Oro/Bundle/AddressBundle/Form/Type/EmailCollectionType.php.
    This collection form type have own renderer https://github.com/laboro/platform/blob/master/src/Oro/Bundle/AddressBundle/Resources/views/Include/fields.html.twig#L138.

    Address entity extends from the AbstractAddress (just like in your case).
    And it have validator for AbstractAddress https://github.com/laboro/platform/blob/master/src/Oro/Bundle/AddressBundle/Resources/config/validation.yml#L20

    This address collection form type we use at create contact page. Here, if you will add sone ibfo to the first address will turn on frontend validators for this entity. You can check this case here http://demo.orocrm.com/desktop/contact/create.

    #13859
    Stepan Yudin
    Stepan Yudin
    Participant

    Yes, you’re totally correct!
    I tried to do like your say about couple of week ago and got strange cache issue. Now everything works like a charm. Thank you!

    And one more question: can i disable client side validation (via jQuery) for specified field/constraint?

    I tried this: form_widget(form.countryPrefixCode,{'attr':{'data-validation':''}}) but in fact it disabled both client side and backend validation. But i need only disable frontend validation

    The full widget code:


    Docker environment for Symfony2/OroCRM/OroBAP development on Windows platform
    https://github.com/stepansib/sf-oro-docker

    #13861
    Stepan Yudin
    Stepan Yudin
    Participant

    I need it in cause of jQuery validator renders error right after the field it casted.
    But i want to render error in specified block in the field widget template


    Docker environment for Symfony2/OroCRM/OroBAP development on Windows platform
    https://github.com/stepansib/sf-oro-docker

    #13871
    Stepan Yudin
    Stepan Yudin
    Participant

    And i found that ClientValidationExtension is looking for option
    'client_validation' => false,
    but it doesnt helped me, client validation fires anyway


    Docker environment for Symfony2/OroCRM/OroBAP development on Windows platform
    https://github.com/stepansib/sf-oro-docker

    #13874

    Hi, @stepan-sib.

    I tried this:
    form_widget(form.countryPrefixCode,{'attr':{'data-validation':''}})
    but in fact it disabled both client side and backend validation. But i need only disable frontend validation

    It looks like your backend validation does not work for this field. Because backend validation can’t be turned off by removing HTML attributes. This attribute is utilized only by frontend validation.

    So, if you want to remove all validation rule for the field with no condition — you can use this approach. But there’s better approach. Same as data-validation-optional-group attribute, there’s other useful attribute — data-validation-ignore. If any field/group of fields is wrapped in element with data-validation-ignore attribute, frontend validator ignores validation rules for this field/group of fields. You can add/remove this attribute in runtime to change validation behavior.

    #13884
    Stepan Yudin
    Stepan Yudin
    Participant

    Hryhorii, such a great tip, you should add it to bundle docs!
    I tried and this works perfect (same as my approach, but my one looks like a hack), thank you a lot!

    And i should agree with you – my backend validation didn’t worked correctly because of i forgot to add Valid constraint to an oro_collection field type. I always forget about something important, my fault)


    Docker environment for Symfony2/OroCRM/OroBAP development on Windows platform
    https://github.com/stepansib/sf-oro-docker

Viewing 8 replies - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.