Menu

Validator conflict with OnChange

Mox
2021-06-09
2025-11-03
  • Mox

    Mox - 2021-06-09

    I have a problem that Validator doesn't get fired because of OnChange action, I don't know why.

    This is my entity:

    @Entity @Getter @Setter
    @EntityValidator(value=NamesValidator.class,
    properties= {
            @PropertyValue(name="id"),
            @PropertyValue(name="name"),
            @PropertyValue(name="childName")})
    public class Names {
        @Id
        @Column(length=7)
        @OnChange(OnChangeNamesIDAction.class)
        private String id;
    
        @Column(length=255)
        private String name;
    
        @ManyToOne(fetch=FetchType.LAZY)
        @DescriptionsList(descriptionProperties="id,name")
        @NoCreate 
        @NoModify
        private childName;
    }
    

    Problem is when I click New, and enter for example 123 in id textbox and click Save, then Validator doesn't show any error message (it validates if name is empty).
    If I click New, and enter for example 123 in id textbox, and then press Tab and then click Save, Validator shows error messge.
    If I remove @OnChange(OnChangeNamesIDAction.class) annotation then Validator works ok.

    What is the problem?

     

    Last edit: Mox 2021-06-09
  • Javier Paniza

    Javier Paniza - 2021-06-14

    Hi Mox,

    when I click New, and enter for example 123 in id textbox and click Save, then Validator doesn't show any error message

    In this case, the record is saved?


    Help others in this forum as I help you.

     
  • Mox

    Mox - 2021-06-14

    No, it's not saved.

     
  • Javier Paniza

    Javier Paniza - 2021-06-16

    Hi Mox,

    So the problem is not the validation, the problem is that because you move the mouse from the textfield to the button, on clicking on the button the event executed is the onchange event, and no the action asociated with the button.

    Do you use the Save button on top or the one on bottom? Does it fail with both?


    Help others in this forum as I help you.

     
  • Mox

    Mox - 2021-06-16

    It fails with both, but interestingly, it seems it works with Ctrl+S.

     

    Last edit: Mox 2021-06-16
  • Javier Paniza

    Javier Paniza - 2021-06-18

    Hi Mox:

    Well, when you click on an action from a field with an event, the action is not executed but only the event. Add it as a bug, I will revise the case.


    Help others in this forum as I help you.

     
  • Javier Paniza

    Javier Paniza - 2025-11-03

    Hi Mox,

    I tried this case, even using your above code as is, with OpenXava 7.6.1 and it works nicely. Now the validation message is shown when click on save, and both the validator and onchange action are executed. So, surely the bug was fixed laterally in some point since the version you were using to the current 7.6.1.

     

Log in to post a comment.

MongoDB Logo MongoDB