Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

MultiSelectField Fix


Reply


28 Posts   5655 Views

Avatar
swaiba

Forum Moderator, 1798 Posts

10 January 2011 at 10:02pm

How about http://www.silverstripe.org/asm-multi-select-field-module/ ?
I haven't tried it, but I'd be interested in your results

Avatar
UncleCheese

4086 Posts

11 January 2011 at 4:04am

I love this module, but I always have to hack it to work with belongs_many_many.

Avatar
Graphicator

Community Member, 62 Posts

23 January 2011 at 12:53pm

When you say hack away at it, do you mean because you get bad responses with Asmselectfield like

ERROR [User Warning]: DataObject::get_by_id passed a non-numeric ID #1,2,3
IN POST /admin/EditForm
Line 2924 in /var/www/vhosts/mysite/httpdocs/sapphire/core/model/DataObject.php

I've got multiselectfield working, but I get bad responses only when I switch to AsmselectField.

Asmselectfield works overall if I only select one member in the dropdown.

Avatar
lx

Community Member, 83 Posts

26 January 2011 at 7:32am

Hi,

i checked the asm Module. (didnt have time earlier)
But this module also gives you a dropdownlist for each available entry.

When I tried it with my 50.000+ enries table, firefox almost crushed.
I had to click "dont´t stop the script" then finally i got the complete list.

$WDL = DataObject::get('WDL');
$asmfield = new AsmselectField('WDL','WDL',$WDL);

In this case an ajax-search would be the only solution, i guess

Avatar
dacar

Community Member, 168 Posts

22 March 2011 at 2:00am

Hi, i unfortunately i have got the same problem as grapicator. Can anybody help?

Avatar
dacar

Community Member, 168 Posts

22 March 2011 at 4:55am

Edited: 22/03/2011 4:56am

Hi, i think the problem is, that function add($item, $extraFields = null) from ComponentSet (line 119) can't handle arrays? Can anybody help to work around?

500//ERROR [User Warning]: DataObject::get_by_id passed a non-numeric ID #1,2
IN POST /admin/EditForm
Line 2924 in /xx/sapphire/core/model/DataObject.php

Source
======
2915:            $tableClasses = ClassInfo::dataClassesFor($callerClass);
2916:            $baseClass = array_shift($tableClasses);
2917:            return DataObject::get_one($callerClass,"\"$baseClass\".\"ID\" = $id", $cache);
2918:
2919:            // This simpler code will be used by non-DataObject classes that implement DataObjectInterface
2920:         } else {
2921:            return DataObject::get_one($callerClass,"\"ID\" = $id", $cache);
2922:         }
2923:      } else {
* 2924:         user_error("DataObject::get_by_id passed a non-numeric ID #$id", E_USER_WARNING);
2925:      }
2926:   }
2927:
2928:   /**
2929:    * Get the name of the base table for this object
2930:    */

Trace
=====
<ul>user_error(DataObject::get_by_id passed a non-numeric ID #1,2,512)
line 2924 of DataObject.php

DataObject::get_by_id(Banner,1,2)
line 119 of ComponentSet.php

ComponentSet->add(1,2)
line 191 of ComponentSet.php

ComponentSet->setByIDList(Array)
line 116 of AsmselectField.php

AsmselectField->saveInto(Page)
line 1021 of Form.php

Avatar
lx

Community Member, 83 Posts

14 July 2011 at 5:40am

Hi,

i faced another issue.
I am using the MultiSelectField in modeladmin.
Everythings looks fine but not in case of validation.
As you know the modeladmin can use getCMSValidator()

The good news is, that my own validation module (NetefxValidator) is working with MultiSelectField.
So i can show validation messages like "you have to choose at least 5 items".
Thats fine.

But there is another strange thing.
The chosen items are not correct after an validation error.
Sometimes there is an item missing, next time 2 more items are chosen or any other unexpexted selection ?!?

it would be very nice if you can fix that, because we definitly need validation in CMS.
With this bug we have to use the CheckboxSetField.

thanks in advance

Avatar
lx

Community Member, 83 Posts

4 August 2011 at 7:51am

I think i got it working in case of a validation error in modeladmin.
The MultiSelectField remembers its selected items.

The funny thing about it is, that i didnt understand what the methode getSelected() is doing in case of !$value.
So i commented it all out :) because it was causing trouble when no item was selected before.

/**
* Get array of selected IDs
*/
public function getSelected() {
   $value = $this->value;
      
// --- uncommenting: Start ---

// If value not set, try to get it from the form
/*
if (!$value && is_object($this->form)) {
$record = $this->form->getRecord();
         if ($record && $record->hasMethod($this->name)) {
            $methodName = $this->name;
            $join = $record->$methodName();
            if ($join) {
               foreach ($join as $joinItem) {
                  $value[] = $joinItem->ID;
               }
            }
         }
      }
*/

// --- uncommenting: End ---

return $value;
}

Also in case of validation the selected items are returned as a string.
So in line 40 i inserted:

// in case of validation we get the selected items as a string, so we have to make an array of it multiselectfield can work with
// --- Start ---
if (!is_array($value)) {
$arr_value = explode(",", $value);
$value = array();
foreach($arr_value AS $v) {
$value[$v] = (int)$v;
}
}
// --- End ---

It seems to work fine.
But commenting so many lines out, lets me think, these line might be needed :)

Maybe you can use this approach to make a better fix.

regards
lx