2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Single checkbox field.
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class CheckboxField extends FormField {
|
|
|
|
/**
|
|
|
|
* Returns a single checkbox field - used by templates.
|
|
|
|
*
|
|
|
|
* Shouldn't this have a value?
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected $disabled;
|
|
|
|
|
|
|
|
function Field() {
|
2008-04-06 06:08:45 +02:00
|
|
|
$attributes = array(
|
|
|
|
'type' => 'checkbox',
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => ($this->extraClass() ? $this->extraClass() : ''),
|
2008-04-06 06:08:45 +02:00
|
|
|
'id' => $this->id(),
|
2008-04-09 13:21:22 +02:00
|
|
|
'name' => $this->Name(),
|
2008-10-25 13:19:31 +02:00
|
|
|
'checked' => $this->value ? 'checked' : '',
|
2008-10-20 12:22:01 +02:00
|
|
|
'tabindex' => $this->getTabIndex()
|
2008-04-06 06:08:45 +02:00
|
|
|
);
|
|
|
|
|
2008-10-20 12:22:01 +02:00
|
|
|
if($this->disabled) $attributes['disabled'] = 'disabled';
|
|
|
|
|
2008-04-06 06:08:45 +02:00
|
|
|
return $this->createTag('input', $attributes);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dataValue() {
|
|
|
|
return $this->value ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checkboxes use the RightLabelledFieldHolder template, to put the field on the left
|
|
|
|
* and the label on the right. See {@link FormField::FieldHolder} for more information about
|
|
|
|
* how FieldHolder works.
|
|
|
|
*/
|
|
|
|
function FieldHolder() {
|
|
|
|
if($this->labelLeft) {
|
|
|
|
return parent::FieldHolder();
|
|
|
|
} else {
|
|
|
|
extract($this->getXMLValues(array( 'Name', 'Field', 'Title', 'Message', 'MessageType' )));
|
|
|
|
$messageBlock = isset($Message) ? "<span class=\"message $MessageType\">$Message</span>" : '';
|
|
|
|
$Type = $this->XML_val('Type');
|
|
|
|
return <<<HTML
|
|
|
|
<p id="$Name" class="field $Type">
|
|
|
|
$Field
|
|
|
|
<label class="right" for="{$this->id()}">$Title</label>
|
|
|
|
$messageBlock
|
|
|
|
</p>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function useLabelLeft( $labelLeft = true ) {
|
|
|
|
$this->labelLeft = $labelLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a restricted field holder used within things like FieldGroups
|
|
|
|
*/
|
|
|
|
function SmallFieldHolder() {
|
|
|
|
$result = $this->Field();
|
|
|
|
if($t = $this->Title()) {
|
|
|
|
$result .= "<label for=\"" . $this->id() ."\">$t</label> ";
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a readonly version of this field
|
|
|
|
*/
|
|
|
|
|
|
|
|
function performReadonlyTransformation() {
|
2007-11-07 03:07:19 +01:00
|
|
|
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value ? 'Yes' : 'No');
|
2007-07-19 12:40:28 +02:00
|
|
|
$field->setForm($this->form);
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
function performDisabledTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
$clone = clone $this;
|
|
|
|
$clone->setDisabled(true);
|
|
|
|
return $clone;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-10 01:34:18 +01:00
|
|
|
/**
|
|
|
|
* Readonly version of a checkbox field - "Yes" or "No".
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class CheckboxField_Readonly extends ReadonlyField {
|
|
|
|
function performReadonlyTransformation() {
|
2008-12-04 23:38:32 +01:00
|
|
|
return clone $this;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setValue($val) {
|
2007-11-07 03:07:19 +01:00
|
|
|
$this->value = ($val) ? 'Yes' : 'No';
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-16 15:44:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Single checkbox field, disabled
|
|
|
|
* @package forms
|
|
|
|
* @subpackage fields-basic
|
|
|
|
*/
|
|
|
|
class CheckboxField_Disabled extends CheckboxField {
|
|
|
|
|
|
|
|
protected $disabled = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a single checkbox field - used by templates.
|
|
|
|
*/
|
|
|
|
function Field() {
|
|
|
|
$attributes = array(
|
|
|
|
'type' => 'checkbox',
|
2008-10-21 22:58:11 +02:00
|
|
|
'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
|
2008-10-16 15:44:05 +02:00
|
|
|
'id' => $this->id(),
|
|
|
|
'name' => $this->Name(),
|
|
|
|
'tabindex' => $this->getTabIndex(),
|
|
|
|
'checked' => ($this->value) ? 'checked' : false,
|
|
|
|
'disabled' => 'disabled'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->createTag('input', $attributes);
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
?>
|