mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-06-28 07:29:26 +02:00
API Substitute Zend_Locale with Locale / NumberFormatter API Substitute Zend_Date with IntlDateFormatter API Added DBTIme::Nice12, FormatFromSettings API Added Short() method to DBDate / DBTime / DBDatetime API Add Date::getTimestamp() API Added setSubmittedValue api for FormField API Add second arg to base FormField::setValue() API Major refactor of i18n into component data parts API Implement Resettable interface to reset objects between tests ENHANCEMENT Changed DBField::create_field return type to `static` to support better type hinting ENHANCEMENT i18nTextCollector supports __CLASS__
52 lines
1.0 KiB
PHP
52 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Forms;
|
|
|
|
/**
|
|
* Single checkbox field.
|
|
*/
|
|
class CheckboxField extends FormField
|
|
{
|
|
|
|
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_BOOLEAN;
|
|
|
|
public function setValue($value, $data = null)
|
|
{
|
|
$this->value = ($value) ? 1 : 0;
|
|
return $this;
|
|
}
|
|
|
|
public function dataValue()
|
|
{
|
|
return ($this->value) ? 1 : null;
|
|
}
|
|
|
|
public function Value()
|
|
{
|
|
return ($this->value) ? 1 : 0;
|
|
}
|
|
|
|
public function getAttributes()
|
|
{
|
|
$attrs = parent::getAttributes();
|
|
$attrs['value'] = 1;
|
|
return array_merge(
|
|
$attrs,
|
|
array(
|
|
'checked' => ($this->Value()) ? 'checked' : null,
|
|
'type' => 'checkbox',
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns a readonly version of this field
|
|
*/
|
|
public function performReadonlyTransformation()
|
|
{
|
|
$field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
|
|
$field->setForm($this->form);
|
|
return $field;
|
|
}
|
|
}
|