mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
BUGFIX Fixed checkboxes checked by default
MINOR Code formatting cleanup MINOR Fixed undefined variable errors and PHP notices
This commit is contained in:
parent
70751f951e
commit
7265fae386
@ -56,7 +56,7 @@ class EditableCheckboxGroupField extends EditableFormField {
|
|||||||
$fieldSet = $this->Options();
|
$fieldSet = $this->Options();
|
||||||
|
|
||||||
$deletedOptions = explode( ',', $data['Deleted'] );
|
$deletedOptions = explode( ',', $data['Deleted'] );
|
||||||
|
$optionNumber = 0;
|
||||||
|
|
||||||
// store default, etc
|
// store default, etc
|
||||||
foreach($fieldSet as $option) {
|
foreach($fieldSet as $option) {
|
||||||
@ -65,16 +65,17 @@ class EditableCheckboxGroupField extends EditableFormField {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $data[$option->ID] )
|
if($data[$option->ID]) {
|
||||||
$option->populateFromPostData( $data[$option->ID] );
|
$option->populateFromPostData( $data[$option->ID] );
|
||||||
|
}
|
||||||
|
|
||||||
unset( $data[$option->ID] );
|
unset( $data[$option->ID] );
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($data as $tempID => $optionData) {
|
foreach($data as $tempID => $optionData) {
|
||||||
|
if(!$tempID || !is_array($optionData) || empty($optionData) || !preg_match('/^_?\d+$/', $tempID)) {
|
||||||
if( !$tempID || !is_array( $optionData ) || empty( $optionData ) || !preg_match('/^_?\d+$/', $tempID ) )
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// what will we name the new option?
|
// what will we name the new option?
|
||||||
$newOption = new EditableCheckboxOption();
|
$newOption = new EditableCheckboxOption();
|
||||||
@ -109,19 +110,9 @@ class EditableCheckboxGroupField extends EditableFormField {
|
|||||||
$optionSet = $this->Options();
|
$optionSet = $this->Options();
|
||||||
$options = array();
|
$options = array();
|
||||||
|
|
||||||
if( $asFilter )
|
$optionMap = ($optionSet) ? $optionSet->map('ID', 'Title') : array();
|
||||||
$options['-1'] = '(Any)';
|
|
||||||
|
|
||||||
$defaultOption = '-1';
|
return new CheckboxSetField($this->Name, $this->Title, $optionMap);
|
||||||
|
|
||||||
/*foreach( $optionSet as $option ) {
|
|
||||||
$options[$option->Title] = $option->Title;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// return radiofields
|
|
||||||
$checkboxSet = new CheckboxSetField( $this->Name, $this->Title, $optionSet, $optionSet );
|
|
||||||
|
|
||||||
return $checkboxSet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValueFromData($data) {
|
function getValueFromData($data) {
|
||||||
@ -129,6 +120,7 @@ class EditableCheckboxGroupField extends EditableFormField {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = '';
|
||||||
$entries = $data[$this->Name];
|
$entries = $data[$this->Name];
|
||||||
|
|
||||||
if(!is_array($data[$this->Name])) {
|
if(!is_array($data[$this->Name])) {
|
||||||
|
@ -36,7 +36,9 @@ class EditableCheckboxOption extends DataObject {
|
|||||||
|
|
||||||
function populateFromPostData($data) {
|
function populateFromPostData($data) {
|
||||||
$this->Title = $data['Title'];
|
$this->Title = $data['Title'];
|
||||||
|
if(isset($data['Default'])) {
|
||||||
$this->setField('Default', $data['Default']);
|
$this->setField('Default', $data['Default']);
|
||||||
|
}
|
||||||
$this->Sort = $data['Sort'];
|
$this->Sort = $data['Sort'];
|
||||||
$this->write();
|
$this->write();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user