NAME
Term::Fabulous::Event::Change - The user changed the value of an input widget
SYNOPSIS
use Clay::UI::Enum::Result;
# On one input:
$name_field->on( Change => sub ($event) {
say 'The name is now: ', $event->value;
return Clay::UI::Enum::Result->CONTINUE; # let ancestors see it too
} );
# Once for a whole form: Change bubbles up from every input inside it.
$form_box->on( Change => sub ($event) {
my $input = $event->target; # the input that changed
printf "%s = %s\n", $input->id, $event->value // 'nothing';
return;
} );
DESCRIPTION
A Change event tells you that the user changed the value of an input widget: by typing into a Term::Fabulous::Widget::TextField or Term::Fabulous::Widget::TextArea, toggling a Term::Fabulous::Widget::Checkbox, selecting a radio button of a Term::Fabulous::Widget::RadioGroup, choosing an option of a Term::Fabulous::Widget::Dropdown, moving a Term::Fabulous::Widget::Slider, choosing the stars of a Term::Fabulous::Widget::StarRating or a segment of a Term::Fabulous::Widget::SegmentedControl.
It is a Clay::UI::Events::Event whose name is Change; listen for it with $widget->on( Change => sub ($event) { ... } ).
Changeis fired only for changes the user makes with the keyboard or the mouse, and for the methods that act "as the user does" ($checkbox->toggle,$group->choose($button),$dropdown->choose($index)). Setting a value from your program ($field->value('x'),$checkbox->checked(1), ...) never fires it.It is fired on the input whose value changed (for radio buttons: on the radio group).
$event->targetis that widget.It bubbles to the ancestors of that widget, so a container can listen once for all the inputs inside it. Bubbling continues past a widget only if that widget has no
Changelisteners, or if every one of itsChangelisteners returnedClay::UI::Enum::Result->CONTINUE. A listener that returns anything else, including a plainreturn;or the value of its last statement, stops the event at that widget. See "Return values and bubbling" in Term::Fabulous::Manual::Events.
CONSTRUCTOR
new
my $event = Term::Fabulous::Event::Change->new( value => $new_value );
You only need the constructor when you write your own input widget; the built-in widgets fire their own events (see "fire_change" in Term::Fabulous::Widget::Input).
value-
Required. The new value, in the form the widget's
valuereader returns it. May beundef.
Unknown parameters die. Like every Clay::UI::Events::Event, an event object can be fired only once.
METHODS
value
my $new_value = $event->value;
The new value of the input, in the form its value reader returns it:
Term::Fabulous::Widget::TextField and Term::Fabulous::Widget::TextArea: the whole text, a character string (lines joined with
"\n"in a text area).Term::Fabulous::Widget::Checkbox:
1(checked) or0(unchecked).Term::Fabulous::Widget::RadioGroup: the
valueof the selected Term::Fabulous::Widget::RadioButton.Term::Fabulous::Widget::Dropdown: the
valueof the chosen option.Term::Fabulous::Widget::Slider: the new number.
Term::Fabulous::Widget::StarRating: the new number of stars.
Term::Fabulous::Widget::SegmentedControl: the
valueof the selected option.
target
my $input = $event->target;
The widget the event was fired on, inherited from Clay::UI::Events::Event. It stays the same while the event bubbles; $event->current_target is the widget whose listeners run right now.
SEE ALSO
Term::Fabulous::Widget::Input, Term::Fabulous::Event::Submit, "FORMS AND INPUT WIDGETS" in Term::Fabulous::Manual::Forms, "EVENTS" in Term::Fabulous::Manual::Events, "Read all values of a form" in Term::Fabulous::Cookbook::Forms, "Choose from options in Perl (Dropdown, RadioGroup, Slider)" in Term::Fabulous::Cookbook::Forms.