Hide Custom Field Type
- This topic has 4 replies, 2 voices, and was last updated 3 months, 3 weeks ago by
Nicholas Cox.
-
AuthorPosts
-
November 24, 2024 at 7:36 PM #47017
Nicholas Cox
ParticipantHi
I have created custom fields and wanted to make it so a custom attribute key and value can show/hide the field input and the field label. So it behaves like the metabox hidden field but with a option to show/hide this. What is the best approach for this? as if I use the custom attribute to hide the input field then the field label is still visible obviously.
here is my custom field code...
public static function html( $meta, $field ) { $required = $field['required'] ?? 0; //metabox field option return sprintf( $html = ' <input id="' . $uniqueID . '" required="' . $required . '" type="text" title="' . $field['field_name'] . '" value="' . $meta . '" name="%s"> ', $field['field_name'], //$field['id'], $meta ); }
thanks
Nick
November 26, 2024 at 6:37 AM #47021Peter
ModeratorHello Nick,
What is the class that you extended to create the custom field type? You can extend any field class to create your own field, add some HTML to the field appearance like a checkbox and create some custom CSS, JS code to show or hide the field. Following the documentation
https://docs.metabox.io/creating-new-field-types/
For example:class RWMB_Custom_Type_Field extends RWMB_Input_Field { public static function html( $meta, $field ) { // Key. $key = isset( $meta[0] ) ? $meta[0] : ''; $attributes = self::get_attributes( $field, $key ); $attributes['placeholder'] = $field['placeholder']['key']; $html = sprintf( '<input %s>', self::render_attributes( $attributes ) ); // Value. $val = isset( $meta[1] ) ? $meta[1] : ''; $attributes = self::get_attributes( $field, $val ); $attributes['placeholder'] = $field['placeholder']['value']; $html .= sprintf( '<input %s>', self::render_attributes( $attributes ) ); $html .= '<input type="checkbox"'; // add your own code to the field appearance. return $html; } }
I hope that makes sense.
November 27, 2024 at 7:58 PM #47037Nicholas Cox
ParticipantHi
Im using
class RWMB_dc_rrule_until_Field extends RWMB_Field
I think im just trying the best way to hide the fields label name too, but not sure how to call this using a custom attribute? Like when you use a hidden field (https://docs.metabox.io/fields/hidden/) it does not display the label, how can i achieve this with a custom field attribute to show/hide this?
hope this makes sense.
November 28, 2024 at 10:26 PM #47055Peter
ModeratorHello Nick,
The field type hidden doesn't have the label, it is different from your custom field where you have the field label and input but can show/hide them. You can follow my suggestion above to create a custom checkbox and show/hide the field by JS code.
If you are not able to complete the task, we offer a customization service. Please contact us here https://metabox.io/contact/ for more details.December 27, 2024 at 8:34 PM #47244Nicholas Cox
Participantok thanks anyway
-
AuthorPosts
- You must be logged in to reply to this topic.