How to set taxonomy advanced options checked/selected on form load?

Support MB Frontend Submission How to set taxonomy advanced options checked/selected on form load?Resolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33483
    Marco NascimentoMarco Nascimento
    Participant

    Hi there,

    I have some taxonomy_advanced fields displayed in a frontend submission form. One of them is a select_advanced field handling a hierarchical two level taxonomy. The others are checkbox_list type fields.

    I'm trying to set selected/checked options on form load using the rwmb_field_meta filter with a callback function that returns a coma separated list of some of the term IDs for the taxonomy (e.g. a string like '10,20,30').

    However, only the first ID in the list is set both on the select_advanced and the checkbox_list fields types. What would be the right way to do this?

    I'm using Frontend Submission and Custom Table extensions. Data saving is working fine in all cases.

    Thanks
    Marco

    #33485
    Long NguyenLong Nguyen
    Moderator

    Hi Marco,

    You can use the setting std to set a default value of the select_advanced field type. For example:

    [
        'name'          => 'Taxonomy',
        'id'            => 'taxonomy',
        'type'          => 'taxonomy_advanced',
        'taxonomy'      => 'category',
        'field_type'    => 'select_advanced',
        'multiple'      => true,
        'std'           => array(2,3,4), //default term IDs
    ],
    #33486
    Marco NascimentoMarco Nascimento
    Participant

    Is it possible to set a function to return this array? I need to get user email (and other data) in order to set the default options array. How could it be done?

    #33496
    Marco NascimentoMarco Nascimento
    Participant

    Hi Long,

    Just to let you know I've got a solution using rwmb_field_meta and setting $meta = array().

    Thank you,
    Marco

    #33499
    Long NguyenLong Nguyen
    Moderator

    Thanks for sharing your solution.

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