@@ -24,14 +24,14 @@ class Editor extends Fluent
2424 use HasEvents;
2525 use HasAuthorizations;
2626
27- public array $ events = [];
28-
2927 const DISPLAY_LIGHTBOX = 'lightbox ' ;
3028 const DISPLAY_ENVELOPE = 'envelope ' ;
3129 const DISPLAY_BOOTSTRAP = 'bootstrap ' ;
3230 const DISPLAY_FOUNDATION = 'foundation ' ;
3331 const DISPLAY_JQUERYUI = 'jqueryui ' ;
3432
33+ public array $ events = [];
34+
3535 /**
3636 * Editor constructor.
3737 *
@@ -156,30 +156,30 @@ public function fields(array $fields): static
156156 }
157157
158158 /**
159- * Set Editor's formOptions.
159+ * Set Editor's bubble formOptions.
160160 *
161161 * @param array $formOptions
162162 * @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
165164 */
166- public function formOptions (array $ formOptions ): static
165+ public function formOptionsBubble (array $ formOptions ): static
167166 {
168- $ this ->attributes ['formOptions ' ] = $ formOptions ;
169-
170- return $ this ;
167+ return $ this ->formOptions (['bubble ' => Helper::castToArray ($ formOptions )]);
171168 }
172169
173170 /**
174- * Set Editor's bubble formOptions.
171+ * Set Editor's formOptions.
175172 *
176173 * @param array $formOptions
177174 * @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
179177 */
180- public function formOptionsBubble (array $ formOptions ): static
178+ public function formOptions (array $ formOptions ): static
181179 {
182- return $ this ->formOptions (['bubble ' => Helper::castToArray ($ formOptions )]);
180+ $ this ->attributes ['formOptions ' ] = $ formOptions ;
181+
182+ return $ this ;
183183 }
184184
185185 /**
@@ -272,4 +272,53 @@ public function toJson($options = 0): string
272272
273273 return Helper::toJsonScript ($ parameters , $ options );
274274 }
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+ }
275324}
0 commit comments