OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions Validation constraints not being applied

This topic contains 16 replies, has 3 voices, and was last updated by  Mike Kudelya 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
  • #34238

    adamlundrigan
    Participant

    I have an entity CourseOffering which has a schedule attached (OneToMany of CourseOfferingTime entities). I want to ensure that (a) there is at least one CourseOfferingTime in the collection, and (b) that the start < end on each CourseOfferingTime.

    CourseOffering#schedule:

    CourseOfferingTime class:

    CourseOfferingType::buildForm contents:

    CourseOfferingScheduleEntryType::buildForm contents:

    validation.yml:

    But none of the constraints are enforced on the client side or on the server side. (eg: if I add an empty CourseOfferingTime to the form I get a DB constraint violation because start is null, whereas I expect to get a form validation error).

    Any thoughts or advice on what I’ve missed in setting up the validation?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Author
    Replies
  • #34239

    Mike Kudelya
    Participant

    Hi,

    I think “- Required” option is not necessary. Try to remove it.

    #34240

    adamlundrigan
    Participant

    I’ve tried this as well:

    Same result. Inspecting the Javascript, the start and end field of each element of the collection have this in the “data-validation” attribute:

    I have another entity with custom validation (validation rules defined in same file, but form is rendered on a different page) and this is what I see when I inspect that field:

    No idea if that’s even relevant.

    #34241

    Mike Kudelya
    Participant

    Hi,

    Be sure that:

    • you clear cache after you make yml changes
    • you are adding four spaces inside each nested yml level
    • you have red * after field label
    • you have datetime input field in span element (it is located just above the main element) with all validation data
    #34242

    adamlundrigan
    Participant

    The validations are being loaded, the fields are labelled with the red star, and the span element for datetime inputs does have the validation rules enumerated there:

    I think it’s a case of the validation not being applied inside the collection. I added a text field and gave it a NotEmpty validator. When I remove the empty row from the collection and try to submit I see this:

    but if I add an empty row to the Schedule collection and submit again I don’t get validation errors on the fields:

    #34243

    Mike Kudelya
    Participant

    One question, why are you using inversedBy=”groups” instead inversedBy=”schedule”? As i can see variable named ‘schedule’..

    #34244

    adamlundrigan
    Participant

    Copy-and-paste error, probably. Thanks for catching that for me ;)

    #34245

    Mike Kudelya
    Participant

    Perhaps i found one solution, add this function to your general CourseOfferingType form. This allows the main form to validate all child.

    #34246

    adamlundrigan
    Participant

    Argh! I knew it would be something simple I was missing. Thanks!

    #34247

    vodvud
    Participant

    Hi!
    I have similar problem.
    But I can’t do to require always.

    Entity Building

    Entity BuildingEstate

    Form type BuildingType

    Form type BuildingEstateType

    Resources/config/validation.yml

    if collection is empty, i don’t see * near ‘name’ and field doesn’t validate

    it is work only if I put some text to any fields

    No idea for fix.

    #34248

    Mike Kudelya
    Participant

    Hi

    Try to move

    from estate field to setDefaultOptions function how i described above.

    #34249

    vodvud
    Participant

    Yes, I tried that. But it also doesn’t work.

    #34250

    Mike Kudelya
    Participant

    Can you tell me, which version of orocrm are you using ? I will try your case and answer a little later.

    #34251

    vodvud
    Participant

    Version 1.10.12

    Validation is works only after submit form, but I see like this one.

    It is not critical problem, but working incorrectly for me.

    #34252

    Mike Kudelya
    Participant

    Hi

    I found workaround. This is not bug, by default works validation for optional group feature, but for now it can disabled only after some coding.

    You can leave the code as is and add opportunity to disable feature:

    Add here:

    Add here:

    Replace this line:

    Add here:

    Add here:

    By default feature behavior remains the same, but if you add this option to your collection field, validation automatically works as you expected.

    #34253

    vodvud
    Participant

    Hi!

    Thank you very much for detailed reply.
    But I think it’s a bad idea to edit a platform on my part, because in the future I will not be able to update the platform.

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

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

Back to top