ssossossosso

Forums

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

This topic contains 16 replies, has 3 voices, and was last updated by Mike Kudelya Mike Kudelya 8 months ago.

  • Creator
    Topic
  • #21541

    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
  • #21579
    Mike Kudelya
    Mike Kudelya
    Oro Core

    Hi,

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

    #21581

    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.

    #21600
    Mike Kudelya
    Mike Kudelya
    Oro Core

    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
    #21602

    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:

    #21603
    Mike Kudelya
    Mike Kudelya
    Oro Core

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

    #21604

    adamlundrigan
    Participant

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

    #21609
    Mike Kudelya
    Mike Kudelya
    Oro Core

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

    #21610

    adamlundrigan
    Participant

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

    #29169
    vodvud
    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.

    #29175
    Mike Kudelya
    Mike Kudelya
    Oro Core

    Hi

    Try to move

    from estate field to setDefaultOptions function how i described above.

    #29219
    vodvud
    vodvud
    Participant

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

    #29739
    Mike Kudelya
    Mike Kudelya
    Oro Core

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

    #29745
    vodvud
    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.

    #29755
    Mike Kudelya
    Mike Kudelya
    Oro Core

    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.

    #29927
    vodvud
    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)

You must be logged in to reply to this topic.