Sandbox: JavaScript

Submits a form when the user changes an input value. Note that the example below is also using the FormRequest Behavior to submit it via Ajax.

Enter some text and tab out of the input.

this box should get new text when you change the input above.
<form id="test"
  data-behavior="FormRequest"
  data-trigger="submitOnChange"
  data-formrequest-update="!body #update"
  data-submitonchange-options="
    'onlyOnce': false
  "
  action="/sandbox/echo_html"
  method="get">
  <p>Enter some text and tab out of the input.</p>
  <div class="form-group">
    <input type="text" name="html" value="" placeholder="Change me." class="form-control input-hg">
  </div>
</form>

<div id="update" class="box">
  this box should get new text when you change the input above.
</div>

Behavior Options

These options apply only to the data- tag invocation.

Name type default description
target string ~ The selector to the form to submit. By default, it expects the element with the behavior to be the form (in which case you can leave this option undefined. If you want a specific input to have this behavior, you can add the behavior to the input and specify !form to submit it.
onlyIfSet boolean false Prevents the form from being submitted if the input is empty.
onlyOnce boolean true Prevents the form from being submitted more than once. You probably want to set this to false if your form is ajaxy and meant to be submitted repeatedly.