Sandbox: JavaScript

Allows you to inject relevant form data depending on which link is clicked to submit it.

Click either submit button to update the box below. The box below them should be updated with the corresponding txt. You don't have to use this trigger in conjunction with the FormRequest behavior as seen here. If you used it with a vanilla form, it would submit it as usual, including the data specified in your trigger options.

fetch html (link 1) fetch html (link 2)

this box should get new text when you click the input above.
<form id="test" data-behavior="FormRequest" data-formrequest-update="!body #update" action="/sandbox/echo_html" method="get">
  <p>
    <input type="submit" name="html" class="btn btn-default" value="fetch html #1"/>
    <input type="submit" name="html" class="btn btn-default" value="fetch html #2"/>
  </p>
  <p>
    <a class="btn btn-xs btn-primary" data-trigger="submitLink"
    	 data-submitlink-extra-data="{'html':'fetch html (link 1)'}">fetch html (link 1)</a>
    <a class="btn btn-xs btn-primary" data-trigger="submitLink"
    	 data-submitlink-extra-data="{'html':'fetch html (link 2)'}">fetch html (link 2)</a>
  </p>
</form>

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

Related Documentation

Note: Not all links in these work.

Delegator Trigger: submitLink

Submits a target form with optional additional data.

Example

<form>
    <input type="text" name="firstName" value="fred"/>
    <a data-trigger="submitLink" data-submitlink-options="'extraData': {'lastName':'Flintstone'}">I'm a Flintstone!</a>
    <a data-trigger="submitLink" data-submitlink-options="'extraData': {'lastName':'Rogers'}">I'm a Rogers!</a>
</form>

Options

  • extraData - (object) Encodes additional data into the form. These are actually added as hidden inputs and then sent along.
  • form - (string; defaults to !form) A selector run through getElement on the element with the trigger specified. Use reversed combinators to search for parents.

Notes

This integrates well with Behavior.FormRequest (the Behavior filter for making forms ajax-y).