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,31 +56,32 @@ 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) {
|
||||||
if( $deletedOptions && array_search( $option->ID, $deletedOptions ) !== false ) {
|
if($deletedOptions && array_search($option->ID, $deletedOptions) !== false) {
|
||||||
$option->delete();
|
$option->delete();
|
||||||
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();
|
||||||
$newOption->Name = 'option' . (string)$optionNumber++;
|
$newOption->Name = 'option' . (string)$optionNumber++;
|
||||||
$newOption->ParentID = $this->ID;
|
$newOption->ParentID = $this->ID;
|
||||||
$newOption->populateFromPostData( $optionData );
|
$newOption->populateFromPostData($optionData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,23 +106,13 @@ class EditableCheckboxGroupField extends EditableFormField {
|
|||||||
return $this->createField( true );
|
return $this->createField( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
function createField( $asFilter = false ) {
|
function createField($asFilter = false) {
|
||||||
$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])) {
|
||||||
|
@ -34,9 +34,11 @@ class EditableCheckboxOption extends DataObject {
|
|||||||
return "Fields[{$this->ParentID}][{$this->ID}]";
|
return "Fields[{$this->ParentID}][{$this->ID}]";
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateFromPostData( $data ) {
|
function populateFromPostData($data) {
|
||||||
$this->Title = $data['Title'];
|
$this->Title = $data['Title'];
|
||||||
$this->setField('Default', $data['Default']);
|
if(isset($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