Support

Account

Home Forums Add-ons Repeater Field add_sub_row, return all rows when complete doesn\'t work

Unread

add_sub_row, return all rows when complete doesn\'t work

  • Hi,

    I’m using ajax to add a subrow to a repeater field and once the subrow is saved, return all subrows.

    It all works great, but the last added subrow isn’t returning, although it is saved).

    Here’s my php code:

    
    if( have_rows('sections', $postID) ):
    while ( have_rows('sections', $postID) ) : the_row();
    if( get_row_layout() == 'comments' ):										$i = add_sub_row("comments",  array(	"comment"	=> $comment, "user" => wp_get_current_user()), $postID) ;
    											if ($i != false) {
    												if( have_rows('comments') ):												while ( have_rows('comments') ) : the_row();
    $response = '<div class="comment">';														$response .= '<div class="user">' . get_sub_field("user")[display_name] . '</div>';														$response .= '<div class="content">' . get_sub_field("comment") . '</div>';													$response .= '</div>';													endwhile;
    												endif;
    											}
    											
    												
    endif;
    endwhile;
    endif;
    echo $response;

    and my js code:

    
    $('.btn-add-comment').click(function(e) {
    			        e.preventDefault();
    			        chapterID = $(this).data("chapterid");
    			        postID = $(this).data("postid");
    			        sectionID = $(this).data("sectionid");
    			       
    					var comment = $("#comments-"+postID+"-"+sectionID + " .user-comment").val();
    					
    			        var data = {
    						'action': 'addcomment',
    						'chapterID': chapterID,
    						'postID' : postID,
    						'sectionID': sectionID,
    						'comment' : comment
    					};
    
    					
    					var j = jQuery.post(ajax_object.ajax_url, data, function(response) {
    						$("#comments-"+postID+"-"+sectionID + " .allcomments").html(response);
    						console.log (response);
    					})
    					.done(function(response) {
    					    console.log ("second success");
    					    console.log (response);
    					});
    
    		        })
    

    any ideas?

Viewing 1 post (of 1 total)

The topic ‘add_sub_row, return all rows when complete doesn\'t work’ is closed to new replies.