php - SilverStripe LookupField always displays "(none)" -


using silverstripe 3.1 trying have form display specific, pre-selected, value instead of having dropdown. since docs indicate lookupfield being situation attempted use it, no matter displays (none) instead of value pass. doesn't appear ever had kind of problems because google doesn't bring useful. either or fail @ using google.

$fields = new fieldlist(...); // $user contact (a dataobject) or null if ($user == null) {     $raw = dataobject::get('contact', 'maycontact = 1', 'sortorder asc');     $list = array();     foreach ($raw $item) {         $list[$item->id] = $item->name . (empty($item->rank) ? '' : ' (' . $item->rank . ')');     }     $sel = new dropdownfield('contact', 'contact', $list); } else {     $list = array();     $list[$user->id] = $user->name . (empty($user->rank) ? '' : ' (' . $user->rank . ')');     $sel = new lookupfield('contact', 'contact', $list); } $fields->insertbefore($sel, 'name'); return new form($this, 'contactform', $fields, new fieldlist(formaction::create('send'))); 

the way see it, should displaying specific contact name (and possibly rank) , array pass same array gets created, difference being has single entry opposed multiple when $user empty.

i should mention still need value passed when form submitted.

you need set value field, not source. value fourth argument constructor, want like:

$sel = new lookupfield('contact', 'contact', $list, $user->id); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -