OptionalabortAllow cancelling of in flight async request if disconnected
ReadonlycontextDefer writing the results while there is interaction with the target container
Tracking of the active error key (e.g. 'error 400') for dispatching & clearing error messages.
ReadonlyhasReadonlyhasReadonlyhasReadonlyhasOptionaliconThe related icon element to attach the spinner to
ReadonlyinputA dotted path to the HTML string value to extract from the JSON response
ReadonlyloadingThe loading state class(es) to apply to the element when a request is in progress.
ReadonlymessagesAn object of messages, where the keys are HTTP status codes, used to determine what message should show in the UI on HTTP error.
OptionalreplaceDebounced function to request a URL and then replace the DOM with the results
OptionalsearchDebounced function to search results and then replace the DOM
OptionalsubmitDebounced function to submit the serialized form and then replace the DOM
OptionalwriteA function that writes the HTML to the target
StaticblessingsStaticclassesStaticdefaultStaticoutletsStatictargetsStaticvaluesElement that receives the fetch result HTML output
StaticshouldWhen disconnecting, ensure we reset any visual related state values and cancel any in-flight requests.
When the error key changes, work out if we need to add a message to the UI or if we just need to clear any existing message that was previously set.
This must be based on the error key but also what message is being used.
Toggle the visual spinner icon if available and ensure content about to be replaced is flagged as busy with a toggling of the loading class.
Abort any existing requests & set up new abort controller, then fetch and replace the HTML target with the new results. Cancel any in progress results request using the AbortController so that a faster response does not replace an in flight request.
OptionalurlSource: string | CustomEvent<{ url: string }> & { params?: { url?: string } }Optionaldata: FormDataPerform a URL search param update based on the input's value with a comparison against the matching URL search params. Will replace the target element's content with the results of the async search request based on the query.
Search will only be performed with the URL param value is different to the input value. Cleared params will be removed from the URL if present.
clear can be provided as Event detail or action param to override the default of 'p'.
Optionaldata: CustomEvent<{ clear: string }> & { params?: { clear?: string } }Update the target element's content with the response from a request based on the input's form values serialized. Do not account for anything in the main location/URL, simply replace the content within the target element.
Staticafter
Allow for an element to trigger an async query that will patch the results into a results DOM container. The controlled element can be the query input, the containing form, or a button. It supports the ability to update the URL with the query when processed or simply make a query based on a form's values.
Example: - A form that will update the results based on the form's input
Example: - A single input that will update the results & the URL
Example: - A single button that will update the results
Example: - A form that will add a global message only when there is a HTTP 400 error
Note: This requires a messages controller to be present in the page, which should be available in the base admin template.
Example: - A form that sets the loading class `is-loading` on the target element when a request is in progress