28/12/2011 1:27am

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


Post Comment