1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 284 Views |
-
DropdownField: can't set value

20 December 2012 at 12:22am Last edited: 20 December 2012 12:47am
If I try to set the current selected value of a dropdown field, nothing happens
I tried it different ways:
$members = Member::get()->map()->toArray();
DropdownField('Test', 'Test', $members, Member::currentUserID());
DropdownField('Test', 'Test', $members)->setValue(Member::currentUserID());
DropdownField('Test', 'Test', $members)->setValue(1);None of these lines above seem to work.
If I call in DropdownField::construct()Debug::dump($this->value);
The correct value is returned. But if I insert the same line of code in DropdownField::Field() I get an empty value back.
Am I missing something or is this just not the way it should work?
-
Re: DropdownField: can't set value

20 December 2012 at 8:13pm
The form value may be overridden later in the process using setValue(), loadDataFrom()
-
Re: DropdownField: can't set value

20 December 2012 at 11:23pm
OK, found the problem:
If I create the Field like this (the name of the field must have "[]" at the end):
DropdownField::create('Test[]', 'Testfield', Member::get()->map('ID', 'Title')->toArray(), 3)->setHasEmptyDefault(true)
I get (as expected) this:
<select name="Test[]" class="chosendropdown chosen" id="BootstrapForm_EditForm_Test">
<option value=""></option>
<option value="2">User 2</option>
<option value="4">User 4</option>
<option value="3" selected="selected">User 3</option>
<option value="1">User 1</option>
</select>But it's somehow strange that i have to add the braces by myself...
| 284 Views | ||
|
Page:
1
|
Go to Top |


