Constructor
new AjaxSubmit()
Properties:
Name | Type | Description |
---|---|---|
no-server-side-error-parsing |
boolean | if set, the response body for a 422 will not be parsed and inserted into the DOM. Instead, the body will be part of the detail of the |
request-timeout |
number | number of ms that the entire operation is expected to complete within. Default is 5000 |
submitted-lifetime |
number | number of ms that "submitted" should remain on the element after the form has completed. Default is 2000 |
requesting |
boolean | boolean attribute that indicates the request has been made, but not yet returned. Don't set this yourself outside of development. It will be set and removed by this element. |
submitted |
boolean | boolean attribute that indicates the form has been successfully submitted. Don't set this yourselr outside of develoment. It will be set and removed by this element. |
log-request-errors |
boolean | if set, logging related to request error handling will appear in the console. It will also cause any form submission to be delayed by 2s to allow you to read the console. |
- Source:
Fires:
- brut:submitok Fired when the AJAX request initated by this returns OK and all processing has completed.event: The detail will include the *parsed document* of the HTML returned in the response.
- brut:submitinvalid Fired when the AJAX request initated by this returns a 422 and all logic around managing the reponse has completed. The detail will be null unless `no-server-side-error-parsing` is set,event: in which case it will be the parsed document of the HTML returned in the response.
Examples
Typical use
<form action="/widgets" method="post">
<input type="text" name="name">
<brut-ajax-submit>
<button name="button" value="save">Save</button>
</brut-ajax-submit>
<brut-ajax-submit>
<button name="button" value="analyze">Analyze</button>
</brut-ajax-submit>
</form>
<!-- When "Save" is clicked, "name" will have the value from the text field,
and "button" will have the value "save".
When "Analyze" is clicked, "name" will have the value from the text
field, and "button" will have the value "analyze". -->
Using a custom abort signal
const ajaxSubmit = document.querySelector("brut-ajax-submit")
const controller = new AbortController()
ajaxSubmit.abortSignal = controller.signal
// later, when you want to abort the request
controller.abort(AjaxSubmit.doNotSubmitThroughBrowser)