masterdany88
masterdany88

Reputation: 5341

Triggering event on input/select value change with Spring web flow

I wanna trigger flow change when user change the value in select box:

<select>
  <options>
    <option>1</option>
    <option>2</option>
  </options>
</select>

After reading this docs: https://docs.spring.io/spring-webflow/docs/current/reference/html/spring-mvc.html#spring-mvc-resuming-on-event I did not find the answer. Please can any one help? Any advice appreciated.

The change I wanna achieve is to set button to be activated, when value has been chosen from select box.

Upvotes: 0

Views: 1619

Answers (1)

rptmat57
rptmat57

Reputation: 3787

there are 2 ways to do this:

First, using strictly javascript (all in the UI), by using onchange and/or onclick on your select element to find the button and activate/deactivate it

Second, using Webflow:

  • submit the form on onchange
  • re-render the view with the proper changes

Assuming you want to go with webflow here, you can use this:

JSP

<form id="myFormId" action="${flowExecutionUrl}" method="post">
    <select id="mySelectId" onchange="Spring.remoting.submitForm('mySelectId', 'myFormId', {fragments:'body', _eventId: 'myChangeEvent'}); return false;">
        ...
    </select>
</form>

Flow

<view-state id="myViewStateId">
    <transition on="myChangeEvent" validate="false" bind="true">
        <!-- change some property to enable your button -->
    </transition>
</view-state>

This will re-render the view and the property/attribute you are using to enable/disable your button will be updated. It is important to use validate="false" otherwise validation error(s) could prevent your transition from succeeding

Upvotes: 1

Related Questions