Disabled radio buttons are editable

Support General Disabled radio buttons are editableResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #39270
    Alaan TVAlaan TV
    Participant

    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',
      ],
    ]
    
    #39274
    PeterPeter
    Moderator

    Hello,

    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/

    #39275
    Alaan TVAlaan TV
    Participant

    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,
    
    #39287
    PeterPeter
    Moderator

    Hello,

    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

    #39522
    Alaan TVAlaan TV
    Participant

    You can run this code once the admin page is loaded to make the readonly radio buttons uneditable:

    document.querySelectorAll('input[type=radio][readonly]')
            .forEach(item => item.addEventListener('click', e => e.preventDefault()));
    
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.