• Resolved rierajf

    (@rierajf)


    Hello,

    Is it possible to insert additional attribute like the example above (data-prix) in an input field generated with your plugin ?

    [checkbox activite_multisports_elementaires data-prix:134 "Multisports élémentaires (CP à CE2) - Lundi - 16h30 / 18h00 - 134 €"]

    Thanks for your help ??

    • This topic was modified 1 year, 6 months ago by rierajf.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @rierajf

    Thank you very much for using our plugin. Yes, that’s possible, but it requires to use the plugin events.

    I’ll try to describe the process with a hypothetical example.

    Assuming you have the checkbox field:

    <label>Posts</label>
    [checkbox posts use_label_element]

    And you want to populate it with the list of website posts, using the post ID as checkbox values and post_title as their texts, and additionally, you want to fill their data-prix attributes with the posts authors’ ids.

    Enter the following form structure:

    <label>Posts</label>
    [checkbox posts use_label_element]
    
    [cf7-recordset id="post-db" type="database" query="SELECT ID, post_author, post_title FROM {wpdb.posts}"]
    [cf7-link-field recordset="post-db" field="posts" value="ID" text="post_title"]
    
    <script>
    jQuery(document).on('change', '[name="posts[]"]', function(evt, attr){
        if(attr == 'cf7-ds-fill') {
            let list = cf7_datasource_get_recordset_data('post-db');
            for(let i in list) {
                jQuery('[name="posts[]"]:eq('+i+')').attr('data-prix', list[i]['post_author']);
            }
        }
    });
    </script>

    The event is triggered after filling in the checkbox choices. It walks through the recordset records and assigns the data-prix attribute to the checkboxes with post_author information.

    Best regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Insert custom additional attributes to an input field’ is closed to new replies.