AnewtFormControlChoice class

Form control for choices.

Class Overview

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:

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.

See also

Public Methods

__construct($name)

Create a new AnewtFormControlChoice instance.

Parameters

$name

The name of this control.

Methods for getting and setting values

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.

Parameters

$values

An associative array from which the form control should be filled.

Return value

true if filling was succesfull, false otherwise.

See also

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.

Return value

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.

Parameters

$value

The 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.

Option methods

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.

Parameters

$option

An AnewtFormOption or AnewtFormOptionGroup instance.

See also

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.

Parameters

$value

The value of this option

$label

The visible name for this option

See also

add_option_group($option_group)

Add an AnewtFormOptionGroup instance to this control.

Parameters

$option_group

An AnewtFormOptionGroup instance.

See also

_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.

Return value

Returns false if there are no enabled controls. Returns true otherwise.

Rendering methods

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.

Return value

XHTML element with the minimal HTML markup needed for this control to function properly.

Public Attributes

$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.

Private Attributes

$_options [private]

List of options.

Note that this list may contain both AnewtFormOption and AnewtFormOptionGroup instances.

Inheritance

Base Classes

Inherited members