@@ -24,14 +24,14 @@ class Editor extends Fluent
24
24
use HasEvents;
25
25
use HasAuthorizations;
26
26
27
- public array $ events = [];
28
-
29
27
const DISPLAY_LIGHTBOX = 'lightbox ' ;
30
28
const DISPLAY_ENVELOPE = 'envelope ' ;
31
29
const DISPLAY_BOOTSTRAP = 'bootstrap ' ;
32
30
const DISPLAY_FOUNDATION = 'foundation ' ;
33
31
const DISPLAY_JQUERYUI = 'jqueryui ' ;
34
32
33
+ public array $ events = [];
34
+
35
35
/**
36
36
* Editor constructor.
37
37
*
@@ -156,30 +156,30 @@ public function fields(array $fields): static
156
156
}
157
157
158
158
/**
159
- * Set Editor's formOptions.
159
+ * Set Editor's bubble formOptions.
160
160
*
161
161
* @param array $formOptions
162
162
* @return $this
163
- * @see https://editor.datatables.net/reference/option/formOptions
164
- * @see https://editor.datatables.net/reference/type/form-options
163
+ * @see https://editor.datatables.net/reference/option/formOptions.bubble
165
164
*/
166
- public function formOptions (array $ formOptions ): static
165
+ public function formOptionsBubble (array $ formOptions ): static
167
166
{
168
- $ this ->attributes ['formOptions ' ] = $ formOptions ;
169
-
170
- return $ this ;
167
+ return $ this ->formOptions (['bubble ' => Helper::castToArray ($ formOptions )]);
171
168
}
172
169
173
170
/**
174
- * Set Editor's bubble formOptions.
171
+ * Set Editor's formOptions.
175
172
*
176
173
* @param array $formOptions
177
174
* @return $this
178
- * @see https://editor.datatables.net/reference/option/formOptions.bubble
175
+ * @see https://editor.datatables.net/reference/option/formOptions
176
+ * @see https://editor.datatables.net/reference/type/form-options
179
177
*/
180
- public function formOptionsBubble (array $ formOptions ): static
178
+ public function formOptions (array $ formOptions ): static
181
179
{
182
- return $ this ->formOptions (['bubble ' => Helper::castToArray ($ formOptions )]);
180
+ $ this ->attributes ['formOptions ' ] = $ formOptions ;
181
+
182
+ return $ this ;
183
183
}
184
184
185
185
/**
@@ -272,4 +272,53 @@ public function toJson($options = 0): string
272
272
273
273
return Helper::toJsonScript ($ parameters , $ options );
274
274
}
275
+
276
+ /**
277
+ * Hide fields on create action.
278
+ *
279
+ * @param array $fields
280
+ * @return $this
281
+ */
282
+ public function hiddenOnCreate (array $ fields ): static
283
+ {
284
+ return $ this ->hiddenOn ('create ' , $ fields );
285
+ }
286
+
287
+ /**
288
+ * Hide fields on specific action.
289
+ *
290
+ * @param string $action
291
+ * @param array $fields
292
+ * @return $this
293
+ */
294
+ public function hiddenOn (string $ action , array $ fields ): static
295
+ {
296
+ $ script = 'function(e, mode, action) { ' ;
297
+ $ script .= "if (action === ' $ action') { " ;
298
+ foreach ($ fields as $ field ) {
299
+ $ script .= "this.hide(' $ field'); " ;
300
+ }
301
+ $ script .= '} else { ' ;
302
+ foreach ($ fields as $ field ) {
303
+ $ script .= "this.show(' $ field'); " ;
304
+ }
305
+ $ script .= '} ' ;
306
+ $ script .= 'return true; ' ;
307
+ $ script .= '} ' ;
308
+
309
+ $ this ->onPreOpen ($ script );
310
+
311
+ return $ this ;
312
+ }
313
+
314
+ /**
315
+ * Hide fields on edit action.
316
+ *
317
+ * @param array $fields
318
+ * @return $this
319
+ */
320
+ public function hiddenOnEdit (array $ fields ): static
321
+ {
322
+ return $ this ->hiddenOn ('edit ' , $ fields );
323
+ }
275
324
}
0 commit comments