Skip to main content

DisableWithController

Purpose

Disable an input/button/link when it is clicked, to prevent double-submissions.

Designed to emulate UJS's data-disable="true" and data-disable-with="Please wait..." for new applications, particularly those using Hotwired.

Actions

ActionPurpose
disableDisable the connected element, cache its default text/label and set its text/label to the messageValue. Repeated calls to disable will simply event.preventDefault to prevent clicks on the disabled event.
enableEnable the connected element, and restore its default text value/label. Calling enable on an element that has not been disabled is a no-op.

Targets

TargetPurposeDefault
---

Classes

ClassPurposeDefault
---

Values

ValueTypeDescriptionDefault
message (Optional)StringThe text to show in the connected element while it is disabled"Submitting..."

Events

EventWhenDispatched onevent.detail
----

Side Effects

Sets an event listener for click on the connected element that fires the disable action.

Sets a timeout using setTimeout with the provided/default timeoutValue.

How to Use

Example - when creating an event that can have the end_time turned off with a boolean: