1
- ## Input examples
1
+ # Input examples
2
2
3
3
> Note: the inputs are rendered by the browser native controls
4
4
9
9
+ This field only supports 6chr hex values as per the W3C spec.
10
10
11
11
``` php
12
+ <?php
12
13
// or ColorField if you are en-us
13
14
$fields->addFieldToTab(
14
- 'Root.Main'
15
+ 'Root.Main',
15
16
ColourField::create('TertiaryColour')
16
17
);
17
18
```
19
+
18
20
### Example HTML
19
21
20
22
``` html
21
23
<input type =" color" id =" field" name =" field" value =" #00bedf" >
22
24
```
23
- If your markdown interpreter renders this, you will see an HTML colour picker field:
24
-
25
- <input type =" color " id =" field " name =" field " value =" #00bedf " >
26
25
27
- < hr >
26
+ Chrome example:
28
27
29
28
![ Colour Field output in Chrome] ( ../img/colourfield.png )
30
29
@@ -43,37 +42,55 @@ With a `<datalist>`, although note that browsers will allow other colours to be
43
42
</datalist >
44
43
```
45
44
46
- Again, an HTML example:
45
+ No need for fancy JS pickers when the browser can do it just as easily. Non supporting browsers will fallback to a text input field.
47
46
48
- <input type =" color " id =" field " name =" field " value =" #00bedf " list =" colours " >
49
- <datalist id =" colours " >
50
- <option >#ff0000</option >
51
- <option >#0000ff</option >
52
- <option >#00ff00</option >
53
- <option >#ffff00</option >
54
- <option >#00ffff</option >
55
- </datalist >
47
+ ### Nullable colour field
56
48
57
- < hr >
49
+ Colour inputs do not allow a null/empty value to be selected. To allow empty values, use the core ` NullableField ` together with a ` ColourField ` , or implement a separate checkbox field:
58
50
59
- No need for fancy JS pickers when the browser can do it just as easily. Non supporting browsers will fallback to a text input field.
51
+ ``` php
52
+ <?php
53
+ $nullableColourField = \SilverStripe\Forms\NullableField::create(
54
+ \Codem\Utilities\HTML5\ColourField::create(
55
+ "CustomColour", "Custom colour"
56
+ ),
57
+ "None"
58
+ );
59
+ ```
60
+
61
+ You will need to apply layout/styling and data handling in your own project.
60
62
61
63
## URL Field
62
64
63
65
A good starting point is the ` URLFieldTest ` class:
64
66
65
67
``` php
68
+ <?php
66
69
$url = 'ftp://www.example.com/path?foo=bar';
67
70
$field = UrlField::create('TestURL', 'Test URL', $url);
68
71
$pattern = "^ftp://.+\.com";
69
72
$phpPattern = "|^ftp://.+\.com|";
70
73
$field->setPattern($pattern, $phpPattern);
71
74
```
72
75
73
- ## Methods available
76
+ ### Methods available
74
77
75
78
+ ` setRequiredParts ` - provide an array of URL parts the URL must have for validation to pass, the values being the keys from ` parse_url() `
76
79
+ ` setPattern ` - set complex and mystifying URL regular expression patterns in both JS and PHP
77
80
+ ` setSchemes ` - set an array of schemes that the URL must start with (eg. ` ['blob', 'dict', 'dns'] ` )
78
81
+ ` restrictToHttp ` - shorthand method, the URL must start with http:// OR https://
79
82
+ ` restrictToHttps ` - shorthand method, the URL must start with https://
83
+
84
+
85
+ ## Traits
86
+
87
+ The fields use relevant traits based on their allowed attributes:
88
+
89
+ + Datalist: for inputs that allow a HTMLDataListElement to be attached
90
+ + MinMax: for inputs that have a min or max
91
+ + Multiple: for inputs that allow multiple selections
92
+ + Pattern: for inputs that support the pattern attribute
93
+ + Step: for inputs that support the step attribute
94
+ + Core: a set of methods for core attributes for all inputs
95
+
96
+ See the RangeField for an example of usage.
0 commit comments