Support › General › Disabled radio buttons are editableResolved
When I set a radio custom field to readonly, I'm still able to edit and save the new value.
'name' => 'My radio',
'id' => 'my_radio',
'type' => 'radio',
'readonly' => true,
'inline' => true,
'options' => [
'option_1' => 'Option 1',
'option_2' => 'Option 2',
For the radio field, please use the setting disabled instead of readonly. Please read more on this link https://support.metabox.io/topic/readonly-attribute-doesnt-work-on-radio-field/
Thank you, Peter, for the prompt response!
The disabled fields will lose their values on Save! I'm getting the values of these fields from an API and saving them in the DB, and I'm using these fields to show the values ONLY to the CMS users.
If the CMS user hit the Save button, all the disabled fields will be reset and lose their values, UNLESS there's a way to pass the original value of the field in the std option.
Do we have a way to pass the current field value in the definition of the custom field? Something like:
'std' => this.value,
You can use the setting std to set the default value for a field. But please be aware that this setting will not work if the field or field group already saved value to the database. Read more on this documentation https://docs.metabox.io/creating-fields-with-code/#why-does-not-my-default-value-work
You can run this code once the admin page is loaded to make the readonly radio buttons uneditable:
.forEach(item => item.addEventListener('click', e => e.preventDefault()));