Template | Problem - dataFieldByName() in Template to find a CompositeField
class MyForm extends Form {
function __construct($controller, $name) {
$fields = new FieldSet();
$RoomsField = new CompositeField();
$RoomsField->setName('RoomsField');
$Rooms = // [ComponentSet]
foreach($Rooms as $i => $Room) {
$SingleRoom = new CompositeField(
// [Fields related to ComponentSet]
);
$RoomsField->push($SingleRoom);
}
$fields->push($RoomsField);
Debug::message($fields->dataFieldByName('RoomsField')); // correctly gets $RoomsField CompositeField
// $actions
// parent::__construct......
}
function forTemplate() {
return $this->renderWith($this->class);
}
// -----------------------------------------------------------
IN TEMPLATE MyForm.ss
// -----------------------------------------------------------
$dataFieldByName(RoomsForm)
//------- OR --------
$FieldByName(RoomsForm)
// both return nothing, however...
<% control Fields %>
$Field
<% end_control %>
// correctly returns $RoomsField CompositeField
// Long story short... how do I access this CompositeField via template, even though 'simplier' fields like TextField or NumericField are accessible via $dataFieldByName()
// bonus points: what if I wanted to get a $SingleRoom by name from within $RoomsField? It's also CompositeField, so wondering if 'stacking' these would cause more problems
28/12/2011 5:36am
Template | Solution - Anonymous
28/12/2011 1:36am
Template | Comment - Anonymous
Sorry, just to be clear: I'm aware lines 37 and 41 are meant to say RoomsField, not RoomsForm. Just a markup I made while posting here, my actual code doesn't have this typo.
The solution to this is
$Fields.fieldByName(RoomsField)
thanks to Smurkas