Form control for choices.
Form control for choices.
This control is a dynamic control that allows the user to make a choice between various alternative options. Options can be added using the add_option() or add_option_value_label() methods (see AnewtFormOption for more information). Option groups can be added using add_option_group() (see AnewtFormOptionGroup for more information).
How this control will be rendered depending on the multiple property (disabled by default) and the threshold property (set to 7 by default). Depending on these values, this control will be shown as:
multiple is false and threshold is not exceeded),multiple is set and threshold is not exceeded),multiple is false and threshold is exceeded; rendering depends on the value of size), ormultiple is true and threshold is exceeded).If the threshold is exceeded the size property is taken into account. If a size is provided (it's null by default), a list of options with the specified size as its height is shown. Setting size on a single select control forces a selection list instead of a dropdown select box in case the threshold is exceeded.
__construct($name) ¶Create a new AnewtFormControlChoice instance.
$nameThe name of this control.
fill($values) ¶Fill the form control from the given values.
This only sets the value for controls for which the can-be-filled property is enabled.
The return value of this function indicates whether the control was successfully filled with a value. For some control types such as checkboxes this always succeeds since both presence and absence of the value from $values are meaningful. For other controls such as text inputs this is only true if the value was actually present in the $values parameters.
$valuesAn associative array from which the form control should be filled.
true if filling was succesfull, false otherwise.
is_valid() ¶Returns if a valid value is supplied.
Very basic validation. Only checks whether exactly one value is supplied for a single choice control.
get_value() [private] ¶Getter method to obtain the selected option values.
External callers should use get('value') instead.
An array values when multiple is enabled, a single value if this is a single select control.
set_value($value) [private] ¶Setter method to enable the correct options.
External callers should use set('value', 'the-value-here') instead.
$valueThe value to set
get_composite() [private] ¶Returns whether this widget is a composite widget.
Choice form control widgets are only composite in certain situations (depending on the mode).
get_composite_for() [private] ¶Returns the id to be used to link labels to widgets.
This method must only be used if this control is composite.
add_option($option) ¶Add an AnewtFormOption or AnewtFormOptionGroup instance to this control.
For simple cases you may want to use add_option_value_label() instead.
$optionAn AnewtFormOption or AnewtFormOptionGroup instance.
add_option_value_label($value, $label) ¶Add a new option to this control.
This is a convenience method to easily add an option to this control. Use add_option() if you want more control over the AnewtFormOption element added to this control.
$valueThe value of this option
$labelThe visible name for this option
add_option_group($option_group) ¶Add an AnewtFormOptionGroup instance to this control.
_ensure_selection() [private] ¶Make sure a valid selection is set.
all_disabled() [private] ¶Check if all options are disabled.
For a single select control, this is the only valid case for having no options enabled.
Returns false if there are no enabled controls. Returns true otherwise.
build_widget() ¶Render the minimal HTML needed for this control to work.
Form control implementations should implement this method, e.g. for a checkbox a simple input HTML element should be returned.
XHTML element with the minimal HTML markup needed for this control to function properly.
$at_least_one_selected ¶Whether this control has at least one selected item.
This flag is for internal use only and is only valid when called directly after setting values.
$_options [private] ¶List of options.
Note that this list may contain both AnewtFormOption and AnewtFormOptionGroup instances.
AnewtContainer::_to_array()AnewtContainer::_add()AnewtContainer::delete()AnewtContainer::get()AnewtContainer::_isset()AnewtContainer::_seed()AnewtContainer::setdefault()AnewtContainer::getdefault()AnewtContainer::set()AnewtContainer::__isset()AnewtContainer::__set()AnewtContainer::is_set()AnewtContainer::add()AnewtContainer::_getdefault()AnewtContainer::__unset()AnewtContainer::seed()AnewtContainer::to_array()AnewtContainer::_get()AnewtContainer::__get()AnewtContainer::keys()AnewtContainer::clear()AnewtContainer::_keys()AnewtContainer::_set()AnewtFormControl::$_validator_errorsAnewtFormControl::get_id()AnewtFormControl::add_validator()AnewtFormControl::is_empty()AnewtFormControl::$_validatorsAnewtFormControl::$_form