You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ChoiceList // refactor internal structure to support "disabled"-attribute for checkbox, radio and options and allow in future to add more settings like "help"-text.
View // complete refactor of markup to move away from <table> and be more flexible with styling elements. All elements on output will now have the "type" as modifier on the wrapper. Additionally the <label> and element itself will now also have a CSS class including the type.
View/Button // introduce new "reset"- and "button"-types which will render a <button>
Copy file name to clipboardexpand all lines: docs/03 - create choices.md
+48-2
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ The `ChoiceElement` allows us to add different choices. This package ships 2 imp
6
6
7
7
To show the differences for both, here's a short example for a `<select>` which shows posts:
8
8
9
-
**1. ArrayChoiceList**
9
+
## `ArrayChoiceList`
10
10
```php
11
11
<?php
12
12
use ChriCo\Fields\Element\ChoiceElement;
@@ -41,7 +41,7 @@ $select = createElement(
41
41
);
42
42
```
43
43
44
-
**2. CallbackChoiceList**
44
+
## `CallbackChoiceList`
45
45
```php
46
46
<?php
47
47
use ChriCo\Fields\Element\ChoiceElement;
@@ -84,3 +84,49 @@ $select = createElement(
84
84
```
85
85
86
86
The main difference is: The `CallbackChoiceList` only loads the choices, when they are first time accessed in view. The `ArrayChoiceList` has already assigned the complete choice-values in it's constructor.
87
+
88
+
## Structure of choices
89
+
90
+
The choices have a new structure since version 2.1 which will be used internally and allows more flexibility.
91
+
92
+
**Old structure** (still works)
93
+
94
+
```php
95
+
use ChriCo\Fields\Element\ChoiceElement;
96
+
use ChriCo\Fields\ChoiceList\ArrayChoiceList;
97
+
$data = [
98
+
'M' => 'Male',
99
+
'F' => 'Female',
100
+
'D' => 'Diverse'
101
+
];
102
+
103
+
// normal ArrayChoiceList
104
+
$select = (new ChoiceElement('select'))
105
+
->withAttributes([ 'type' => 'select' ])
106
+
->withChoices(new ArrayChoiceList($data));
107
+
```
108
+
109
+
**New structure**
110
+
```php
111
+
use ChriCo\Fields\Element\ChoiceElement;
112
+
use ChriCo\Fields\ChoiceList\ArrayChoiceList;
113
+
$data = [
114
+
'M' => [
115
+
'label' => 'Male',
116
+
'disabled' => true,
117
+
],
118
+
'F' => [
119
+
'label' => 'Female',
120
+
]
121
+
'D' => [
122
+
'label' => 'Diverse'
123
+
]
124
+
];
125
+
126
+
// normal ArrayChoiceList
127
+
$select = (new ChoiceElement('select'))
128
+
->withAttributes([ 'type' => 'select' ])
129
+
->withChoices(new ArrayChoiceList($data));
130
+
```
131
+
132
+
As you can see we now have instead of `array<string|int, string>` mapping a more complex structure `array<string|int, array<{ label: string, disabled?:boolean }>`, which will allow us to additionally set `disabled`. The result is the same, but the "old structure" will be internally converted to "new structure".
0 commit comments