AnewtFormControlChoice Class Reference

Form control for choices. More...

List of all members.

Public Member Functions

 __construct ($name)
 Create a new AnewtFormControlChoice instance.
Rendering methods
 build_widget ()
 Render the minimal HTML needed for this control to work.

Public Attributes

 $at_least_one_selected
 Whether this control has at least one selected item.

Private Attributes

 $_options = array()
 List of options.

Methods for getting and setting values

 fill ($values)
 Fill the form control from the given values.
 is_valid ()
 Returns if a valid value is supplied.
 get_value ()
 Getter method to obtain the selected option values.
 set_value ($value)
 Setter method to enable the correct options.
 get_composite ()
 Returns whether this widget is a composite widget.
 get_composite_for ()
 Returns the id to be used to link labels to widgets.

Option methods

 add_option ($option)
 Add an AnewtFormOption or AnewtFormOptionGroup instance to this control.
 add_option_value_label ($value, $label)
 Add a new option to this control.
 add_option_group ($option_group)
 Add an AnewtFormOptionGroup instance to this control.
 _ensure_selection ()
 Make sure a valid selection is set.
 all_disabled ()
 Check if all options are disabled.


Detailed Description

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:
AnewtFormOption

Definition at line 140 of file choice.lib.php.


Constructor & Destructor Documentation

AnewtFormControlChoice::__construct ( name  ) 

Create a new AnewtFormControlChoice instance.

Parameters:
$name The name of this control.

Reimplemented from AnewtFormControl.

Definition at line 168 of file choice.lib.php.


Member Function Documentation

AnewtFormControlChoice::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.
Returns:
true if filling was succesfull, false otherwise.
See also:
AnewtForm::fill()

Reimplemented from AnewtFormControl.

Definition at line 183 of file choice.lib.php.

AnewtFormControlChoice::get_value (  )  [private]

Getter method to obtain the selected option values.

External callers should use get('value') instead.

Returns:
An array values when multiple is enabled, a single value if this is a single select control.

Definition at line 212 of file choice.lib.php.

AnewtFormControlChoice::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

Definition at line 246 of file choice.lib.php.

AnewtFormControlChoice::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).

Definition at line 302 of file choice.lib.php.

AnewtFormControlChoice::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.

Definition at line 314 of file choice.lib.php.

AnewtFormControlChoice::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.

Reimplemented from AnewtFormControl.

Definition at line 325 of file choice.lib.php.

AnewtFormControlChoice::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

AnewtFormOption

AnewtFormOptionGroup

Definition at line 352 of file choice.lib.php.

AnewtFormControlChoice::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

AnewtFormOption

Definition at line 387 of file choice.lib.php.

AnewtFormControlChoice::add_option_group ( option_group  ) 

Add an AnewtFormOptionGroup instance to this control.

Parameters:
$option_group An AnewtFormOptionGroup instance.
See also:
add_option

AnewtFormOptionGroup

Definition at line 402 of file choice.lib.php.

AnewtFormControlChoice::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:
Returns false if there are no enabled controls. Returns true otherwise.

Definition at line 442 of file choice.lib.php.

AnewtFormControlChoice::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.

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

Reimplemented from AnewtFormControl.

Definition at line 459 of file choice.lib.php.


Member Data Documentation

AnewtFormControlChoice::$_options = array() [private]

List of options.

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

Definition at line 150 of file choice.lib.php.

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

Definition at line 159 of file choice.lib.php.


The documentation for this class was generated from the following file:

Generated on Sun Aug 2 22:54:37 2009 for Anewt by  doxygen 1.5.9