BUGFIX Fixed checkboxes checked by default

MINOR Code formatting cleanup
MINOR Fixed undefined variable errors and PHP notices
This commit is contained in:
Sean Harvey 2009-01-28 05:59:23 +00:00
parent 70751f951e
commit 7265fae386
2 changed files with 18 additions and 24 deletions

View File

@ -56,7 +56,7 @@ class EditableCheckboxGroupField extends EditableFormField {
$fieldSet = $this->Options();
$deletedOptions = explode( ',', $data['Deleted'] );
$optionNumber = 0;
// store default, etc
foreach($fieldSet as $option) {
@ -65,16 +65,17 @@ class EditableCheckboxGroupField extends EditableFormField {
continue;
}
if( $data[$option->ID] )
if($data[$option->ID]) {
$option->populateFromPostData( $data[$option->ID] );
}
unset( $data[$option->ID] );
}
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;
}
// what will we name the new option?
$newOption = new EditableCheckboxOption();
@ -109,19 +110,9 @@ class EditableCheckboxGroupField extends EditableFormField {
$optionSet = $this->Options();
$options = array();
if( $asFilter )
$options['-1'] = '(Any)';
$optionMap = ($optionSet) ? $optionSet->map('ID', 'Title') : array();
$defaultOption = '-1';
/*foreach( $optionSet as $option ) {
$options[$option->Title] = $option->Title;
}*/
// return radiofields
$checkboxSet = new CheckboxSetField( $this->Name, $this->Title, $optionSet, $optionSet );
return $checkboxSet;
return new CheckboxSetField($this->Name, $this->Title, $optionMap);
}
function getValueFromData($data) {
@ -129,6 +120,7 @@ class EditableCheckboxGroupField extends EditableFormField {
return "";
}
$result = '';
$entries = $data[$this->Name];
if(!is_array($data[$this->Name])) {

View File

@ -36,7 +36,9 @@ class EditableCheckboxOption extends DataObject {
function populateFromPostData($data) {
$this->Title = $data['Title'];
if(isset($data['Default'])) {
$this->setField('Default', $data['Default']);
}
$this->Sort = $data['Sort'];
$this->write();
}