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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

CustomSearchContext


Go to End


1136 Views

Avatar
tomjohn

Community Member, 19 Posts

29 October 2015 at 4:42am

I've got two fields in custom form which work as dropdown : Birth and death date

My code is:

class Senator extends DataObject
{
	static $db = array (
                'BirthYear'			=>	'Int',
		'DEathYear'			=>	'Int',
....
)
}

and

public function getCustomSearchContext() {
{
	static $db = array (
               $fields->push(new DropdownField('BirthYear', 'Birth Year',   Dataobject::get("Senator","","BirthYear ASC")->map("BirthYear", "BirthYear")));
               $fields->push(new DropdownField('DeathYear', 'Death Year', Dataobject::get("Senator","","DeathYear ASC")->map("DeathYear", "DeathYear", "Please Select")));
....
)
}

I'm looking for solution for two my problems:
1. I've got a lot of duplicates in years. I'm removing it jquery now, but it would be great to get it propertlly from system
2. How can I make third field with how old was each person? DeathYear - BirthYear ? I tried several ways but I have: Fatal error: Call to a member function setValue() on a non-object in /framework/search/filters/SearchFilter.php on line 194 always.

Anyone can help?