Announcement Announcement Module
Collapse
No announcement yet.
AJAX request + validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AJAX request + validation

    Hi,

    I'm trying to perform form validation for an AJAX request. Here is my scenario.

    For example if I have an employer form model which contains the main fields (e.g: address) and a list of employees.

    The employer form contains another form to manage an employee.

    The related view is mapped to my employer model like this:

    Code:
    <view-state id="employer" view="employer" model="employerForm">
       <transition on="save" to="whatever">
         <evaluate expression="employerService.update(employerForm.getEmployer()" />
       </transition>
    
       <!-- AJAX -->
       <transition on="addEmployee" validate="false">
         <evaluate expression="employerForm.getEmployees().add(employerForm.getEmployeeForm().getEmployee())" />
         <render fragments="employees" />
       </transition>
    
    </view-state>
    My view contains 2 transitions. The first transition is to save the employer and its dependencies. The second is to add a new employee which is handled with an AJAX request and the employees fragment is refreshed.

    Everything works perfectly until I'm plugging the validation on my model.
    I'm using the annotated validation on my employer form (JSR 303).

    The problem is if I'm validating the 'addEmployee' transition; I'm getting validation on the main field. I would like to perform only the validation on the submit employee form (return from the AJAX request).

    I've used the @Valid on the employee association to propagate the validation. When I'm pressing save; it validates my empty employee form which is wrong. And when I'm adding an employee; it validates the parent fields...

    Is it a way to validate only the employee form? It'll be nice to register a set of binders inside a transition...


    Cheers,
    Ced.
Working...
X