Promise-enabled buttons. PromiseButton is a component that will take a promise, render as a button, and when clicked, will trigger the promise and then show its state once the promise has either resolved or rejected. To read more on promises go here.

Usage:

<FwPromiseButton @class="btn btn-sm" @promise={{action 'callServer'}}>
    Click Me!
</FwPromiseButton>

The promise variable is a closure action that must return a promise. If not, unexpected behavior may occur. The promise option is the only one that needs to be specified.

When should you use the promise-button as opposed to HTML generic button? General rule of thumb, if the action needs to call a network request, then it should return a promise and use a promise button. If it doesn’t call a network request, then it should use the plain button HTML tag.

Show:

autoWidth

Boolean

Boolean value that tells whether or not the button's width needs to stay constant regardless of state.


Default: true

buttonIcon

String

If you want a button-icon to be displayed, put any of the font-awesome icons as a string here. Must use full icon name, including the class


Default: ''

buttonState

Computed private

This returns the buttonStyle based on the state that the button is in. If success, it is a success class; if error, danger class; and otherwise it is the normal button class. Watches: buttonStyle, state.

buttonStyle

String

This is the style of the button. This corresponds to button states in Bootstrap. Can be set to 'primary', 'default', 'success', 'danger', 'info', 'warning', or 'link'. For more information on Bootstrap button states, click here.


Default: 'primary'

buttonText

String

If you are rendering the promise button as an inline component and not in block form, set this to whatever text you want the button to display. If you are rendering in block form, this does not apply.


Default: ''

concatenatedClasses

Computed private

This returns a string of all the classes to be set on the main element. Specifically the button state, joined to all the other classes. Watches: buttonState, class.

disableWhen

Boolean

External control for the disabled state of the button. This is different than the regular disabled setting because the state of the button will automatically modify whether or not the button is spinning based on whether or not the promise is in the process of running.


Default: false

onsuccess

Action

Action to call when the promise is succesful

progress

Number

Sets the progress percent of the button. Used with submitting to show a sort of progress bar. Must be a number between 0 and 100, setting to null disables it.


Default: null

promise

String | Function

Promise function (either using a string or a closure function) This is an absolute requirement. Also the action should resolve the promise (using RSVP), as detailed in the Ember guides linked above.

showStateTimeout

Unknown private

Holds the Ember.run function responsible for resetting the state of a button after the specified timeout.


Default: null

showSuccess

Boolean

If true, show the green checkmark when the promise button is successful


Default: true

spinIcon

String

Sets the icon to be shown when the promise is resolving. See here for a list of possible icons.


Default: 'fa-solid fa-rotate'

state

Object private

Holds the state of the button. Can be an empty object (no state, promise has not been clicked), rejected (promse has rejected), or resolved (promise has resolved)

submitting

Boolean private

Private instance variable holding whether or not the button is currently submitting the promise. Used to modify the spinning state of FwSpinButton


Default: false

timeout

Number

The time that the state of the button should be shown before returning to default. Time must be specified in milliseconds.


Default: 3000