ssossossosso

Forums

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

This topic contains 4 replies, has 3 voices, and was last updated by vodvud vodvud 7 months, 1 week ago.

  • Creator
    Topic
  • #29985
    vodvud
    vodvud
    Participant

    Hi!

    I have 2 fields firstName and lastName

    validation.yml

    I need so that one field can be empty, but can’t both.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #30402
    Mike Kudelya
    Mike Kudelya
    Oro Core

    Hi

    Try to create class constraint validator. As example i can show you constraint and validator.

    #32590
    vodvud
    vodvud
    Participant

    Hi!

    I found another way

    Thank you!

    #32604

    Hi @vodvud,

    Problem that you are trying to mange looks ordinary, but solution here is not so trivial.

    Solution that you use, might work for most cases. But I would not say it is reliable. There’s a lot of cons. Starting from, that you’re using js-inline code, the handler lives in memory despite that user already left edit page. And ending, that you are handling only click on submit buttons, but a form can be submitted in other ways, e.g. by keydown an enter key on some text field.

    I would propose you to create own constraint here, different from ‘NotBlank’ (because it validates only current field). You need a validator rule that works with two fields at same time. Similar to how works validation on “Re-Enter Password”, see Repeated constraint
    https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/FormBundle/Resources/public/js/validator/repeated.js#L14. Validation function should look for other field and returns a result in depends of what aggregated value is. To add new validation rule to validator use following approach https://github.com/orocrm/platform/blob/master/src/Oro/Bundle/EmailBundle/Resources/public/js/app/modules/email-module.js#L13-L13

    #32646
    vodvud
    vodvud
    Participant

    Hi!
    You’re right, I’ll try your way.
    Thank you!

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

You must be logged in to reply to this topic.