Jump to:

10993 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » MultiValueField

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 177 Views
  • Lukereative
    Community Member
    8 Posts

    MultiValueField Link to this post

    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).

    See SortableObjectSection.php
    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’);

    See 30.png

    And it is stored in the database like so

    See 31.png

    See SortableObject.php
    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);

    See 32.png

    This is how it’s stored in the database

    See 33.png

    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.

    Attached Files
  • Lukereative
    Community Member
    8 Posts

    Re: MultiValueField Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.