10809 Posts in 2495 Topics by 1783 members
|Go to End|
20 January 2014 at 6:48pm Last edited: 20 January 2014 6:50pm
I am currently trying to develop a website using SilverStripe with the silverstripe-multivaluefield module.
I managed to mostly figure out how to wrangle it to do what I wanted but I ran into an issue when I use the data from a MultiValueField to populate a MultiValueCheckboxField.
What I am trying to achieve is being able define categories for a set of objects (for example books able to be set to Fantasy or Action), these books are stored as data objects (SortableObject) and are related to a page (SortableObjectPage).
I first set the categories using a MultiValueTextField on the SortableObjectPage and store the values in MultiValueField.
$fields->addFieldToTab('Root.Main', new MultiValueTextField('Categories'), 'Metadata’);
And it is stored in the database like so
I then access the ‘Categories’ MultiValueField and use it to populate a MultiValueCheckboxField when creating a SortableObject
$parentCategories = $this->SortableObjectSection()->Categories->Value;
$categoriesField = new MultiValueCheckboxField('RelatedCategories', 'Related Categories', $parentCategories);
This is how it’s stored in the database
This is where my problem is, instead of storing the strings such as ‘Fantasy’ or ‘Action’ it simply stores a number (I think it’s the index of the category in the array used to populate the Checkboxes) as the string in the database, which means I can’t access the strings on the template I am trying to make.
I have also attached the two files that define SortableObjectSection and SortableObject as txt files but they are usually php files.
21 January 2014 at 2:14pm
This was resolved with an update to the module after talking to the repository maintainer.
I was able to add:
To the MultiValueCheckboxField and this meant that the proper strings were stored.
|Go to Top|