Select_advanced field with ajax - get current label

Support General Select_advanced field with ajax - get current label

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #37181
    wgstjfwgstjf
    Participant

    Hi guys,

    We have a select_advanced field that is sourcing it's options via ajax. The ajax function gets and formats data from a custom table (used by MB Custom Table). We can successfully get and save data this way.

    The issue is that I cannot see how to get and display the previously saved value's label. Our select_advanced field is in a cloneable group so it is not easy to just get the stored value from the database and then do a DB lookup to get hte label. Any thoughts??

    
    array(
    	'name' 	=> __( 'Event Name', 'indigo-metaboxes' ),
    	'id'   	=> 'event_id',
    	'type'  => 'select_advanced',
    	'options' => '', // presumably need a function here that can get the current value and do a DB query for the value to display...
    	'js_options' => array (
        'ajax' => array(
          'url' => admin_url('/admin-ajax.php?action=get_events_list'),
          'dataType' => 'json',
          'type' => 'get',
          'delay' => '250',
        ),
        'minimumInputLength' => 3,
        'allowClear' => true,
        'placeholder' => 'Choose event...'
      ),
    	'columns'  => '4',
    ),
    

    Thanks in advance,

    Will

    #37231
    Long NguyenLong Nguyen
    Moderator

    Hi Will,

    Did you try to use the helper function rwmb_get_field_settings() to get the field/subfield setting? Please read more on the documentation https://docs.metabox.io/functions/rwmb-get-field-settings/

    #37300
    wgstjfwgstjf
    Participant

    Hi Long

    Thanks for your reply though I'm not sure I understand.

    I need to be able to get the stored field's Value, for each select_advanced field within the cloneable group, and then do a DB lookup to get the Label (to display as the selected option) from a custom table.

    In theory we could do something like this

    
    // Field Option
    'options' => get_current_option(currentValue),
    
    // Function
    function get_current_option(currentValue) {
     // DB Lookup to get Label for value...
     $example_label = 'Test;
     // Response
     return [currentValue => $example_label];
    }
    

    The issue is I have no idea how to get the 'currentValue' var for the 'select_advanced' field in each of the cloneable groups. Any advice?

    Cheers,

    Will

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.