Home Forums Backend Issues (wp-admin) Append dynamic choices to specific field(radio buttons)


Append dynamic choices to specific field(radio buttons)

  • Hi.
    – WordPress Ver. 5.4.1
    – ACF Ver. 5.8.11
    – Post editor: Gutenberg

    I created a field group which contains following fields.

    – Text field [text]
    – Button field [custom field]
    – Radio button field [radio] : This field has just one choice by default. Later append choices via AJAX.

    When I click the button, get a data from the text field and pass it to my custom JS to get JSON data from a remote server. So far I successfully get JSON data and display it in my browser console.

    What I want to do next is to use this JSON data to add radio button choices in same block, but there seems to be no filters return HTML suitable for the radio button field.

    I looked through core functions and found the file includes/fields/class-acf-field-radio.php which has member function render_field but no hooks.

    I think this is used for HTML output.
    line 135:

    $e .= '<li><label' . $class . '><input ' . acf_esc_attr( $atts ) . '/>' . $label . '</label></li>';

    Is there any way to pass my JSON data to this function and get HTML?

    I could manually make HTML and insert it by JS but there is no ID or class to target.

    Radio buttons output is like following:

    <ul class="acf-radio-list acf-hl" id="NEED-SOME-UNIQUE-ID-HERE!">
          <input type="radio" id="acf-block_XXXXX-field_YYYYY" name="acf-block_XXXX[field_YYYY]" value="">LABEL

    Any help will be appreciated.

  • I found some solution to my own question.
    I could use render_field hook to modify wrapper ID or class to give a form unique name so that I can target specific field to insert HTML.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Append dynamic choices to specific field(radio buttons)’ is closed to new replies.