Support

Account

Home Forums Add-ons Repeater Field JS "append" action and some value in new field

Solved

JS "append" action and some value in new field

  • Hello, I have a repeater field and try to add generated value to the filed when new row is adding trough ADD button.
    I put the code to separate file and all logs fire fine. But when I add new row my field is still empty.

    This code is situated in JS file.

     acf.add_action('append', function( $el ){
            // $el will be equivalent to the new element being appended $('tr.row')
            
            var setvalue = jQuery('#post_ID').val() + 'h';
            
            // find a specific field
            var $field = $el.find('.acf-field-5995fe2ea9aad');
            $field.val(setvalue);
    
        });
  • For some reason I thought that I should give the value to $field object, just didn`t know to what key.

    At this moment I ended with this

    acf.add_action('append', function( $el ){
            /* $el will be equivalent to the new element being appended $('tr.row') */
            var setvalue = jQuery('#post_ID').val() + 'h' + (new Date().getTime()).toString(36);
            var $row = $el.closest('.acf-row');       
            $row.find('.acf-field-5995fe2ea9aad input').val(setvalue);
        });

    to add new value to the field. It shows the value in field.
    Important – I add disabled attribute to the field via JS and it was not saved to database, be careful.

  • Thanks so much for this teraviva, it was a very useful starting point for me to use the append JS hook.

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

The topic ‘JS "append" action and some value in new field’ is closed to new replies.