7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » [SOLVED] FilteredDropdownSet - not filtered
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1409 Views |
-
[SOLVED] FilteredDropdownSet - not filtered

19 February 2012 at 1:32pm Last edited: 19 February 2012 1:42pm
Hi,
I have a problem with FilteredDropdownSetI have three DataObject
Two is Province and Twon
Third is Simple ObjectI have that code
Province.php
class Province extends DataObject
{static $db = array (
'Title' => 'Varchar(255)',
);static $field_labels = array(
'Title' => 'Województwo'
);}
and
Town.php
class Town extends DataObject
{static $db = array (
'Title' => 'Varchar(255)',
);static $has_one = array (
'Province' => 'Province',
);static $has_many = array (
'Anonse' => 'Anons',
);static $field_labels = array(
'Title' => 'Miasto'
);
}and DataObject Anons.php (he display in frontpage)
class Anons extends DataObject
{.................
static $has_one = array(
'Province' => 'Province',
'Town' => 'Town'
);//Fields to search in ModelAdmin
static $searchable_fields = array (
'Province.ID' => array('title' => 'Województwo'),
'Town.ID' => array('title' => 'Miasto'),
);function getCMSFields()
{
$fields = parent::getCMSFields();....................
//Main Tab
$fields->removeByName('Province');
$fields->removeByName('Town');
$province_map = array();
$town_map = array();
if($result = DataObject::get("Province")) {
$province_map = $result->toDropdownMap();
}
if($result = DataObject::get("Town")) {
$town_map = $result->toDropdownMap();
}
$fields->addFieldToTab("Root.Main", new FilteredDropdownSet(array(
new DropdownField('ProvinceID', 'Province', $province_map),
new DropdownField('TownID', 'Town', $town_map)
),
"ProvinceID",
"Town"
));
return $fields;
}.........................
public function getCustomSearchContext() {
$province_map = array();
$town_map = array();
if($result = DataObject::get("Province")) {
$province_map = $result->toDropdownMap();
}
if($result = DataObject::get("Town")) {
$town_map = $result->toDropdownMap();
}
$fields = new FieldSet(
new FilteredDropdownSet(array(
new DropdownField('ProvinceID', 'Province', $province_map),
new DropdownField('TownID', 'Town', $town_map)
),
"ProvinceID",
"Town"
)
);
$filters = array(
'Province' => new ExactMatchMultiFilter('Province.ID'),
'Town' => new ExactMatchMultiFilter('Town.ID'),
);
return new SearchContext(
$this->class,
$fields,
$filters
);}
Neither in the frontend or backend filtering does not work.
I mean when for example I point on province "lodzkie" in second field (Town) not filtered - allways display all TwonSorry for my bad English
-
Re: [SOLVED] FilteredDropdownSet - not filtered

3 May 2012 at 11:30pm Last edited: 3 May 2012 11:30pm
The problem is in the FieldSet. FilteredDropdownSet does not work inside a FieldSet nor a FieldGroup. I had that same problem, f*ck*ng nightmare. Try it out like this :
$filter = new FilteredDropdownSet(array(
new DropdownField('ProvinceID', 'Province', $province_map),
new DropdownField('TownID', 'Town', $town_map)
),
"ProvinceID",
"Town"
);$fields->addFieldToTab("Root.Main", $filter);
Be sure to fully populate the $province_map and $town_map.
Cheers, hope it works.
-
Re: [SOLVED] FilteredDropdownSet - not filtered

17 October 2012 at 1:47pm
Hi,
I did not have when check thisLooks like it works
Many thank'sYou are right - this is f*ck*ng nightmare
Sorry for bad English
| 1409 Views | ||
|
Page:
1
|
Go to Top |


