@@ -80,14 +80,17 @@ public function __construct($name, $title = null, $sourceKeys = [], $sourceValue
80
80
81
81
public function Field ($ properties = [])
82
82
{
83
- if (Controller::curr () instanceof ContentController) {
84
- Requirements::javascript ('silverstripe/admin: thirdparty/jquery/jquery.js ' );
83
+ if (Controller::has_curr ()
84
+ && (Controller::curr () instanceof ContentController)
85
+ && MultiValueTextField::config ()->get ('output_jquery_on_frontend ' )
86
+ ) {
87
+ Requirements::javascript ('https://code.jquery.com/jquery-3.6.3.min.js ' );
85
88
}
86
89
Requirements::javascript ('symbiote/silverstripe-multivaluefield: client/javascript/multivaluefield.js ' );
87
90
Requirements::css ('symbiote/silverstripe-multivaluefield: client/css/multivaluefield.css ' );
88
91
89
- $ nameKey = $ this ->name . '[key][] ' ;
90
- $ nameVal = $ this ->name . '[val][] ' ;
92
+ $ nameKey = $ this ->name . '[key][] ' ;
93
+ $ nameVal = $ this ->name . '[val][] ' ;
91
94
$ fields = [];
92
95
$ keyFieldPlaceholder = $ this ->getKeyFieldPlaceholder ();
93
96
$ valueFieldPlaceholder = $ this ->getValueFieldPlaceholder ();
@@ -96,20 +99,20 @@ public function Field($properties = [])
96
99
foreach ($ this ->value as $ i => $ v ) {
97
100
if ($ this ->readonly ) {
98
101
$ fieldAttr = [
99
- 'class ' => 'mventryfield mvkeyvalReadonly ' . ($ this ->extraClass () ? $ this ->extraClass () : '' ),
100
- 'id ' => $ this ->id (). MultiValueTextField::KEY_SEP . $ i ,
102
+ 'class ' => 'mventryfield mvkeyvalReadonly ' . ($ this ->extraClass () ? $ this ->extraClass () : '' ),
103
+ 'id ' => $ this ->id () . MultiValueTextField::KEY_SEP . $ i ,
101
104
'name ' => $ nameKey ,
102
105
'tabindex ' => $ this ->getAttribute ('tabindex ' )
103
106
];
104
107
105
108
$ keyField = HTML ::createTag ('span ' , $ fieldAttr , Convert::raw2xml ($ i ));
106
- $ fieldAttr ['id ' ] = $ this ->id (). MultiValueTextField::KEY_SEP . $ v ;
109
+ $ fieldAttr ['id ' ] = $ this ->id () . MultiValueTextField::KEY_SEP . $ v ;
107
110
$ valField = HTML ::createTag ('span ' , $ fieldAttr , Convert::raw2xml ($ v ));
108
- $ fields [] = $ keyField. $ valField ;
111
+ $ fields [] = $ keyField . $ valField ;
109
112
} else {
110
113
$ keyField = $ this ->createSelectList ($ i , $ nameKey , $ this ->sourceKeys , $ i , $ keyFieldPlaceholder );
111
114
$ valField = $ this ->createSelectList ($ i , $ nameVal , $ this ->sourceValues , $ v , $ valueFieldPlaceholder );
112
- $ fields [] = $ keyField. ' ' . $ valField ;
115
+ $ fields [] = $ keyField . ' ' . $ valField ;
113
116
}
114
117
}
115
118
} else {
@@ -119,14 +122,12 @@ public function Field($properties = [])
119
122
if (!$ this ->readonly ) {
120
123
$ keyField = $ this ->createSelectList ('new ' , $ nameKey , $ this ->sourceKeys , '' , $ keyFieldPlaceholder );
121
124
$ valField = $ this ->createSelectList ('new ' , $ nameVal , $ this ->sourceValues , '' , $ valueFieldPlaceholder );
122
- $ fields [] = $ keyField. ' ' . $ valField ;
123
- // $fields[] = $this->createSelectList('new', $name, $this->source);
125
+ $ fields [] = $ keyField . ' ' . $ valField ;
126
+ // $fields[] = $this->createSelectList('new', $name, $this->source);
124
127
}
125
128
126
- return '<ul id=" ' .$ this ->id ().'" class="multivaluefieldlist mvkeyvallist ' .$ this ->extraClass ().'"><li> ' .implode (
127
- '</li><li> ' ,
128
- $ fields
129
- ).'</li></ul> ' ;
129
+ return '<ul id=" ' . $ this ->id () . '" class="multivaluefieldlist mvkeyvallist ' . $ this ->extraClass () . '"><li> '
130
+ . implode ('</li><li> ' , $ fields ) . '</li></ul> ' ;
130
131
}
131
132
132
133
protected function createSelectList ($ number , $ name , $ values , $ selected = '' , $ placeholder = '' )
@@ -136,7 +137,7 @@ protected function createSelectList($number, $name, $values, $selected = '', $pl
136
137
[
137
138
'selected ' => $ selected == '' ? 'selected ' : '' ,
138
139
'value ' => ''
139
- ],
140
+ ],
140
141
''
141
142
);
142
143
@@ -150,8 +151,8 @@ protected function createSelectList($number, $name, $values, $selected = '', $pl
150
151
151
152
if (count ($ values ?? [])) {
152
153
$ attrs = [
153
- 'class ' => 'text mventryfield mvdropdown ' . ($ this ->extraClass () ? $ this ->extraClass () : '' ),
154
- 'id ' => $ this ->id (). MultiValueTextField::KEY_SEP . $ number ,
154
+ 'class ' => 'text mventryfield mvdropdown ' . ($ this ->extraClass () ? $ this ->extraClass () : '' ),
155
+ 'id ' => $ this ->id () . MultiValueTextField::KEY_SEP . $ number ,
155
156
'name ' => $ name ,
156
157
'tabindex ' => $ this ->getAttribute ('tabindex ' )
157
158
];
@@ -163,8 +164,8 @@ protected function createSelectList($number, $name, $values, $selected = '', $pl
163
164
return HTML ::createTag ('select ' , $ attrs , $ options );
164
165
} else {
165
166
$ attrs = [
166
- 'class ' => 'text mventryfield mvtextfield ' . ($ this ->extraClass () ? $ this ->extraClass () : '' ),
167
- 'id ' => $ this ->id (). MultiValueTextField::KEY_SEP . $ number ,
167
+ 'class ' => 'text mventryfield mvtextfield ' . ($ this ->extraClass () ? $ this ->extraClass () : '' ),
168
+ 'id ' => $ this ->id () . MultiValueTextField::KEY_SEP . $ number ,
168
169
'value ' => $ selected ,
169
170
'name ' => $ name ,
170
171
'tabindex ' => $ this ->getAttribute ('tabindex ' ),
0 commit comments