17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 130 Views |
-
Dropdown fields state not saved

11 December 2011 at 10:36am
Anyone had a problem with FilteredDropdownSet? I’ve got it listing the categories and items correctly and the selection is saved correctly, but when editing, the dropdowns don’t select the saved item. I suppose it has to do with that AvailableProduct.php thing, but how exactly is the class and the has_ones in it supposed to be named?
-
Re: Dropdown fields state not saved

13 December 2011 at 7:56pm
static $has_one = array(
'Foo' => 'FooClass' // creates a column 'FooID'
);
..$fields->push(new DropdownField('FooID', 'Foo'..)
Make sure you use FooID as the field name not Foo as you're referring to the relationship column value (which is stored as Name + ID)
-
Re: Dropdown fields state not saved

14 December 2011 at 12:42am
Thanx! Problem actually appears, when you use two drop downs inside FilteredDropdownSet. One dropdown works nicely - but... Idea is to create main categories to dropdown 1 and products based on selected item from dropdown 1 to appear in dropdown 2. Selection works nicely: items are printed nicely on the dropdowns but when hitting the save, products (in drop down 2) is back to default value.
Hope you got the idea and figured out the problem?
-
Re: Dropdown fields state not saved

14 December 2011 at 6:54am Last edited: 14 December 2011 6:56am
That form field does have one minor drawback, and that's that you have to redundantly store the value of the parent ID, as well. Let's look at an example with Towns and Regions. Towns have a parent Region. A Place is in a Town, and we'll use a FilteredDropdownSet to choose a region first, then the town.
class Town extends DataObject
{static $db = array (
'Title' => 'Varchar(255)',
);static $has_one = array (
'Region' => 'Region',
);}
class Region extends DataObject
{static $db = array (
'Title' => 'Varchar(255)',
);}
Place.php
static $has_one = array (
'Region' => 'Region',
'Town' => 'Town'
);new FilteredDropdownSet(
array(
$region = new DropdownField('RegionID','Region',$map_of_regions),
$town = new DropdownField('TownID','Town',$map_of_towns)
),
"RegionID",
"Town"
)As you can see, the field RegionID is redundant on the Place object because we know it by transference through the TownID. It's a little annoying, but unfortunately it just works best that way in order to support the native functions of SilverStripe forms.
---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com -
Re: Dropdown fields state not saved

4 January 2012 at 1:11pm
Make sure you use FooID as the field name not Foo as you're referring to the relationship column value (which is stored as Name + ID)
Thanks Willr. This was my exact issue this morning.
| 130 Views | ||
|
Page:
1
|
Go to Top |


