Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 950f28b

Browse files
committedJul 13, 2017
Added function to define lorem ipsum fields faster
1 parent 8abaf32 commit 950f28b

File tree

2 files changed

+67
-38
lines changed

2 files changed

+67
-38
lines changed
 

‎code/controllers/StyleGuideController.php

+55
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,59 @@ public function Paragraphs($count = 5)
117117
$lorem = new joshtronic\LoremIpsum();
118118
return $lorem->paragraphs($count);
119119
}
120+
121+
public function Field($type = 'TextField', $attributes = null)
122+
{
123+
$uniqid = uniqid();
124+
$optionFields = array(
125+
'DropdownField',
126+
'CheckboxSetField',
127+
'OptionsetField',
128+
'ListboxField',
129+
'LookupField',
130+
'TagField'
131+
);
132+
$name = str_ireplace('Field', '', $type);
133+
$name = preg_replace('/([A-Z])/', ' $1', $name);
134+
if (in_array($type, $optionFields)) {
135+
$options = array();
136+
for ($i=0; $i < 3; $i++) {
137+
$options[$i] = $this->Words($i+1);
138+
}
139+
$field = $type::create($uniqid, $name, $options);
140+
} else {
141+
$field = $type::create($uniqid, $name);
142+
}
143+
if ($attributes) {
144+
if (strpos($attributes, ';') !== FALSE){
145+
$attributes = explode(';', $attributes);
146+
} else {
147+
$attributes = array($attributes);
148+
}
149+
foreach ($attributes as $attribute) {
150+
if (strpos($attribute, ':') !== FALSE){
151+
list($attribute, $value) = explode(':', $attribute);
152+
}
153+
switch (strtolower($attribute)) {
154+
case 'required':
155+
case 'require':
156+
$field->addExtraClass($attribute);
157+
break;
158+
case 'title':
159+
case 'label':
160+
$field->setTitle($value);
161+
break;
162+
default:
163+
$field->setAttribute($attribute, $value);
164+
break;
165+
}
166+
}
167+
}
168+
return Form::create(
169+
$this,
170+
$uniqid,
171+
FieldList::create(array($field)),
172+
FieldList::create(array())
173+
);
174+
}
120175
}

‎templates/Styles/text_fields.ss

+12-38
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,12 @@
1-
<fieldset>
2-
<div class="field-container">
3-
<label for="text">Text Input <abbr title="Required">*</abbr></label>
4-
<input id="text" placeholder="Text Input" type="text">
5-
</div>
6-
<div class="field-container">
7-
<label for="password">Password</label>
8-
<input id="password" placeholder="Type your Password" type="password">
9-
</div>
10-
<div class="field-container">
11-
<label for="webaddress">Web Address</label>
12-
<input id="webaddress" placeholder="http://yoursite.com" type="url">
13-
</div>
14-
<div class="field-container">
15-
<label for="emailaddress">Email Address</label>
16-
<input id="emailaddress" placeholder="name@email.com" type="email">
17-
</div>
18-
<div class="field-container">
19-
<label for="search">Search</label>
20-
<input id="search" placeholder="Enter Search Term" type="search">
21-
</div>
22-
<div class="field-container">
23-
<label for="text">Number Input <abbr title="Required">*</abbr></label>
24-
<input id="text" placeholder="Enter a Number" pattern="[0-9]*" type="number">
25-
</div>
26-
<div class="field-container">
27-
<label for="textarea">Textarea</label>
28-
<textarea id="textarea" rows="8" cols="48" placeholder="Enter your message here"></textarea>
29-
</div>
30-
<div class="field-container">
31-
<label class="error">Error Input</label>
32-
<input class="is-error" placeholder="Text Input" type="text">
33-
</div>
34-
<div class="field-container">
35-
<label class="valid">Valid</label>
36-
<input class="is-valid" placeholder="Text Input" type="text">
37-
</div>
38-
</fieldset>
1+
$Field('TextField')
2+
$Field('TextField','class:invalid error;title: Invalid input')
3+
$Field('TextareaField','required;placeholder:Enter your message here')
4+
$Field('NumericField','required')
5+
$Field('PasswordField')
6+
$Field('EmailField')
7+
$Field('TimeField')
8+
$Field('DateField')
9+
$Field('DropdownField')
10+
$Field('CheckboxField')
11+
$Field('CheckboxSetField')
12+
$Field('OptionsetField')

0 commit comments

Comments
 (0)
Please sign in to comment.