A number field with a minus and a plus, for a quantity that is changed a step at a time (hours, seats, days):
the buttons are disabled at the limits, the field is a spinbutton that says its value and its limits, and
typing in it works as well. The LiveView keeps the value: it learns of a press in event (with phx-value-step
-1 or 1) and of typing in the field's own phx-change.
step/4 and clamp/3 are the arithmetic, so the server applies the same rule the buttons suggest.
Summary
Functions
value inside min and max; a limit that is nil does not apply.
value moved by direction (-1 or 1) steps, and kept inside min and max.
Functions
value inside min and max; a limit that is nil does not apply.
Attributes
id(:string) (required)name(:string) (required)value(:integer) (required)label(:string) (required) - what is counted, for assistive technology.min(:integer) - Defaults tonil.max(:integer) - Defaults tonil.step(:integer) - Defaults to1.event(:string) (required) - sent by the buttons, withphx-value-step.decrease_label(:string) (required)increase_label(:string) (required)disabled(:boolean) - Defaults tofalse.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
minus_icon(required)plus_icon(required)
value moved by direction (-1 or 1) steps, and kept inside min and max.