mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API Add isDisabledValue to SelectField
API Remove deprecated {comma} syntax for multi select string encoded values API MemberDatetimeOptionsetField now has a fixed preview date BUG fix inverted arguments in OptionSetField::getOptionClass
This commit is contained in:
parent
bdb1a95758
commit
99de74d69e
@ -96,7 +96,7 @@ class DropdownField extends SingleSelectField {
|
||||
|
||||
// Check disabled
|
||||
$disabled = false;
|
||||
if(in_array($value, $this->getDisabledItems()) && $title != $this->getEmptyString()){
|
||||
if($this->isDisabledValue($value) && $title != $this->getEmptyString()){
|
||||
$disabled = 'disabled';
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,14 @@ class MemberDatetimeOptionsetField extends OptionsetField {
|
||||
|
||||
const CUSTOM_OPTION = '__custom__';
|
||||
|
||||
/**
|
||||
* Non-ambiguous date to use for the preview.
|
||||
* Must be in 'y-MM-dd HH:mm:ss' format
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $preview_date = '25-12-2011 17:30:00';
|
||||
|
||||
public function Field($properties = array()) {
|
||||
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/MemberDatetimeOptionsetField.js');
|
||||
$options = array();
|
||||
@ -53,15 +61,27 @@ class MemberDatetimeOptionsetField extends OptionsetField {
|
||||
$option->setField('CustomName', $this->getName().'[Custom]');
|
||||
$option->setField('CustomValue', $this->Value());
|
||||
if($this->Value()) {
|
||||
$preview = Convert::raw2xml(Zend_Date::now()->toString($this->Value()));
|
||||
$preview = Convert::raw2xml($this->previewFormat($this->Value()));
|
||||
$option->setField('CustomPreview', $preview);
|
||||
$option->setField('CustomPreviewLabel', _t('MemberDatetimeOptionsetField.Preview', 'Preview'));
|
||||
}
|
||||
return $option;
|
||||
}
|
||||
|
||||
public function getItemName() {
|
||||
return parent::getItemName() . '[Options]';
|
||||
/**
|
||||
* For a given format, generate a preview for the date
|
||||
*
|
||||
* @param string $format Date format
|
||||
* @return string
|
||||
*/
|
||||
protected function previewFormat($format) {
|
||||
$date = $this->config()->preview_date;
|
||||
$zendDate = new Zend_Date($date, 'y-MM-dd HH:mm:ss');
|
||||
return $zendDate->toString($format);
|
||||
}
|
||||
|
||||
public function getOptionName() {
|
||||
return parent::getOptionName() . '[Options]';
|
||||
}
|
||||
|
||||
public function Type() {
|
||||
|
@ -147,10 +147,8 @@ abstract class MultiSelectField extends SelectField {
|
||||
if($result !== false) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Parse data in legacy {comma} format
|
||||
Deprecation::notice('4.0', 'Storing multi-selection values in comma separated format is deprecated');
|
||||
return str_replace('{comma}', ',', explode(',', $value));
|
||||
|
||||
throw new \InvalidArgumentException("Invalid string encoded value for multi select field");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,27 +61,50 @@ class OptionsetField extends SingleSelectField {
|
||||
* @return ArrayData Field option
|
||||
*/
|
||||
protected function getFieldOption($value, $title, $odd) {
|
||||
// Check selection
|
||||
$selected = $this->isSelectedValue($value, $this->Value());
|
||||
$itemID = $this->ID() . '_' . Convert::raw2htmlid($value);
|
||||
$extraClass = $odd ? 'odd' : 'even';
|
||||
$extraClass .= ' val' . Convert::raw2htmlid($value);
|
||||
|
||||
return new ArrayData(array(
|
||||
'ID' => $itemID,
|
||||
'Class' => $extraClass,
|
||||
'Name' => $this->getItemName(),
|
||||
'ID' => $this->getOptionID($value),
|
||||
'Class' => $this->getOptionClass($value, $odd),
|
||||
'Name' => $this->getOptionName(),
|
||||
'Value' => $value,
|
||||
'Title' => $title,
|
||||
'isChecked' => $selected,
|
||||
'isDisabled' => $this->isDisabled() || in_array($value, $this->getDisabledItems()),
|
||||
'isChecked' => $this->isSelectedValue($value, $this->Value()),
|
||||
'isDisabled' => $this->isDisabledValue($value)
|
||||
));
|
||||
}
|
||||
|
||||
protected function getItemName() {
|
||||
/**
|
||||
* Generate an ID property for a single option
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function getOptionID($value) {
|
||||
return $this->ID() . '_' . Convert::raw2htmlid($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the "name" property for each item in the list
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getOptionName() {
|
||||
return $this->getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extra classes for each item in the list
|
||||
*
|
||||
* @param string $value Value of this item
|
||||
* @param bool $odd If this item is odd numbered in the list
|
||||
* @return string
|
||||
*/
|
||||
protected function getOptionClass($value, $odd) {
|
||||
$oddClass = $odd ? 'odd' : 'even';
|
||||
$valueClass = ' val' . Convert::raw2htmlid($value);
|
||||
return $oddClass . $valueClass;
|
||||
}
|
||||
|
||||
|
||||
public function Field($properties = array()) {
|
||||
$options = array();
|
||||
$odd = false;
|
||||
|
@ -58,6 +58,19 @@ abstract class SelectField extends FormField {
|
||||
return $this->disabledItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given value is disabled
|
||||
*
|
||||
* @param string $value
|
||||
* @return bool
|
||||
*/
|
||||
protected function isDisabledValue($value) {
|
||||
if($this->isDisabled()) {
|
||||
return true;
|
||||
}
|
||||
return in_array($value, $this->getDisabledItems());
|
||||
}
|
||||
|
||||
public function getAttributes() {
|
||||
return array_merge(
|
||||
parent::getAttributes(),
|
||||
|
@ -3,6 +3,7 @@
|
||||
<option value="$Value.XML"
|
||||
<% if $Selected %> selected="selected"<% end_if %>
|
||||
<% if $Disabled %> disabled="disabled"<% end_if %>
|
||||
><% if $Title %>$Title.XML<% else %> <% end_if %></option>
|
||||
><% if $Title %>$Title.XML<% else %> <% end_if %>
|
||||
</option>
|
||||
<% end_loop %>
|
||||
</select>
|
||||
|
Loading…
Reference in New Issue
Block a user