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.

Form Questions /

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

Rendering a CompositeField in tempate via dataFieldByName()


Go to End


4 Posts   2195 Views

Avatar
mikhail

Community Member, 4 Posts

28 December 2011 at 1:39pm

Hi there, long time lurker first time poster.

Here's my problem in a nutshell http://www.sspaste.com/paste/show/4efa627a0f228
I have put my questions at the bottom of the snippet.

I'm a designer by trade, so a simple problem like this is much bigger for me than most of you, I'm sure. Thank you in advance : )

Avatar
MarcusDalgren

Community Member, 288 Posts

28 December 2011 at 5:22pm

Ok bonus question first since that one's easy: $dataFieldByName() still works even though the fields are in a composite field, at least that's what the docs say.

The crux of $fieldByName() (first letter is lower case) is that it's defined on the FieldSet class and not the Form class. Doing something like

 
<% control Fields %>
$fieldByName(RoomsField)
<% end_control %>

Should work. Hope that helps.

Avatar
mikhail

Community Member, 4 Posts

28 December 2011 at 5:32pm

Edited: 28/12/2011 5:33pm

I tried

<% control Fields %>
$fieldByName(RoomsField)
<% end_control %>

before, but that didn't work. Your point about FieldSet/Form classes made me try a couple more things, though.
This is what ended up working:

$Fields.fieldByName(RoomsField)

Which is bizzare, since it's the same thing? (or is it?)
I gave up on this not long after I posted this question, but your reply made me revisit this and I'm happy it did. Thank you! Have a good New Years : D

Avatar
MarcusDalgren

Community Member, 288 Posts

29 December 2011 at 1:30am

Yes that's really bizzare since they are supposed to be the same thing. I'm glad it worked out!