Support

Account

Forum Replies Created

  • EDIT: Nevermind. All is still working!

  • Trasek… mind sharing? I’m trying to do the same thing…

  • I was able to solve this by not re-inventing the wheel.

    What I did was simply use the Repeater field, but I added some JavaScript to auto-add the first row if the field’s minimum is set to a negative number and there are no rows added…

    
    /*! FLEXIBLE/REPEATER: AUTO-ADD ITEM IF EMPTY **/
    acf.add_action('ready append', function($body){
      var $fields = $body.find('.acf-field-flexible-content, .acf-field-repeater');
      var $target = $fields.find('.acf-flexible-content, .acf-repeater').filter('.empty, .-empty').filter(function(){
        if ($(this).data('min') !== 0 && $(this).parents('.clones, .acf-clone').length === 0) {
          return true;
        }
      });
      if ($target.length > 0) {
        var $button = $target.find('> ul').find('> li').find('> .acf-button').filter('[data-event="add-layout"], [data-event="add-row"]');
        $button.click();
      }
    });
    

    Then I added some CSS to hide all the functionality on the Repeater field itself (so I hide the add, remove, collapse buttons).

    
    /*! ACF: FAUX FLEXIBLE/REPEATER */
    .acf-field-flexible-content .acf-flexible-content[data-min^="-"] > ul > li > .acf-button,
    .acf-field-flexible-content .acf-flexible-content[data-min^="-"] > .layout > .acf-fc-layout-handle,
    .acf-field-flexible-content .acf-flexible-content[data-min^="-"] > .layout > .acf-fc-layout-controlls,
    .acf-field-repeater .acf-repeater[data-min^="-"] > ul > li > .acf-button,
    .acf-field-repeater .acf-repeater[data-min^="-"] > table > tbody > tr > .acf-row-handle {
      display: none;
    }
    
    .acf-field-repeater .acf-repeater[data-min^="-"] > table > tbody > tr > .acf-fields {
      border-left-width: 0;
    }
    

    Now I have the ability to group my content by leveraging the Repeater field! I’m not going to lie, the CSS may not be 100% complete — it works for my scenario, but there may be other scenarios I haven’t tested yet.

  • For now I am handling this with some simple front-end JS…

    
    /*! FLEXIBLE CONTENT: AUTO-CLICK IF SINGLE OPTION **/
    acf.add_action('ready', function($body){
      $body.find('#post').on('click', 'a[data-event="add-layout"]', function(){
        var $button = $(this);
        var $target = $button.parents('.acf-flexible-content').eq(0).find('.clones').find('.layout');
        if ($target.length === 1) {
          setTimeout(function(){
            var $popup = $button.next('.acf-fc-popup');
            $popup.find('a').eq(0).click();
            $popup.remove();
          }, 0);
        }
      });
    });
    
  • Here’s a mock of the layout I am trying to achieve…

    http://postimg.org/image/lamafxz5z/

    Note how the middle column is a group of fields. Could do this with a Repeater field but I do not want the user to be able to add more than 1, and I want one there by default.

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