Select / Select advanced read-only/disabled
- This topic has 6 replies, 5 voices, and was last updated 3 weeks, 6 days ago by
Peter.
-
AuthorPosts
-
September 9, 2022 at 7:25 PM #38248
Jean-Michel Junod
ParticipantMetabox AIO v.1.16.4
Using Metabox Builder for custom fields for USER.
Problems with read-only/disabled and saving values:Select field:
read-only: it is still possible to change value and save it
disabled: current value is lost after savingSelect advanced (same):
read-only: it is still possible to change value and save it
disabled: current value is lost after savingInput field also loose value after saving if "disabled".
Feature request for input/select fields:
- property "protected" or "locked" that would replace the field value with just a <div class="rwmb-input">[value]</div> or something that would prevent user to inspect/edit page html and update disable/readonly attributesSeptember 11, 2022 at 3:55 AM #38257sherwin_flight
ParticipantYou can use some JavaScript to remove the disabled attribute when you save, and then the values will be saved as expected.
But I think a read only/locked option would be great. I'm struggling with a similar issue right now as well, only with clone groups that i want to be read only.
September 11, 2022 at 9:10 PM #38260Long Nguyen
ModeratorHi,
For the select field, you can use the setting
disableto prevent the user from selecting the option and set the default value for the field to save the field value to the database. For example:[ 'name' => __( 'Select', 'your-text-domain' ), 'id' => 'select_67b3inmhfgs', 'type' => 'select', 'options' => [ 'a' => __( 'A', 'your-text-domain' ), 1 => __( '1', 'your-text-domain' ), 2 => __( '2', 'your-text-domain' ), 3 => __( '3', 'your-text-domain' ), ], 'std' => 2, 'disabled' => true, ],October 1, 2026 at 8:10 AM #50222Ruth Hutchins
ParticipantHi wanted to check if there is an update on this?
I have a select field which I do not want to be changed directly from the admin interface. But I do want the value to be visible.
I set disabled = true as a custom attribute, which partially works, in the sense that the select box becomes visible but grayed out/can't be changed.
However, then if I update anything else and submit, the select field is cleared. I do not want it to go back to a default value. I want it to keep its current value. What's the best way to do this?
October 1, 2026 at 8:59 PM #50223Peter
ModeratorHello Ruth,
Thanks for reaching out.
The default value of the select field will be applied to a new post. If you want to change the value of a post, you can try:
- removedisableattribute in the field settings
- edit a post and select another value > save post
- add thedisableattribute againIf it doesn't work, can you please share a screen record of the issue on your site?
October 2, 2026 at 12:24 AM #50225Ruth Hutchins
ParticipantHey - That would probably work but wouldn't be a good UX for the users!
What I ended up doing was leaving the field with disabled=true and adding a hidden input with the current value:
`
... {
add_filter( 'rwmb_status_end_html', array( $this, 'add_status_hidden_input' ), 10, 3 );
}
...
public function add_status_hidden_input( string $html, mixed $field, mixed $value ) {
$html .= '<input type="hidden" name="status" value="' . esc_attr( $value ) . '">';
return $html;
}
`Is there a reference for the allowed keys in $field[]? I think $field['id'] would work instead of hard coding the field name? $field['name'] is the label, right?
October 3, 2026 at 8:42 AM #50226Peter
ModeratorHello,
Yes, you can use the field setting ID as
$field['id']. Here is the list of field settings https://docs.metabox.io/field-settings/ -
AuthorPosts
- You must be logged in to reply to this topic.