From 1eaf45a118aaa5840acef7c856c399bffc65f783 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 22 Dec 2011 14:56:38 +0100 Subject: [PATCH] MINOR Documentation for FormField->setTemplate() and FormField->setAttribute() --- docs/en/topics/forms.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/en/topics/forms.md b/docs/en/topics/forms.md index a0499fe88..56cda31b5 100644 --- a/docs/en/topics/forms.md +++ b/docs/en/topics/forms.md @@ -155,9 +155,7 @@ Readonly on a FormField $myReadonlyField = $myField->performReadonlyTransformation(); -## Using a custom template - -*Required Silverstripe 2.3 for some displayed functionality* +## Custom form templates You can use a custom form template to render with, instead of *Form.ss* @@ -239,6 +237,27 @@ To find more methods, have a look at the `[api:Form]` class, as there is a lot o templates, for example, you could use `<% control Fields %>` instead of specifying each field manually, as we've done above. +### Custom form field templates + +The easiest way to customize form fields is adding CSS classes and additional attributes. + + :::php + $field = new TextField('MyText'); + $field->addExtraClass('largeText'); + $field->setAttribute('data-validation-regex', '[\d]*'); + + // Field() renders as: + // + +Each form field is rendered into a form via the `[FieldHolder()](api:FormField->FieldHolder())` method, +which includes a container `
` as well as a `