OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions How to make non strict client validation for 2 fields?

This topic contains 4 replies, has 3 voices, and was last updated by  vodvud 7 years, 2 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
  • #34338

    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
  • #34339

    Mike Kudelya
    Participant

    Hi

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

    #34340

    vodvud
    Participant

    Hi!

    I found another way

    Thank you!

    #34341

    Hryhorii Hrebiniuk
    Participant

    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

    #34342

    vodvud
    Participant

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

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

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

Back to top