Support

Account

Home Forums Add-ons Flexible Content Field When only one layout available, the "Add" button should not have options popup Reply To: When only one layout available, the "Add" button should not have options popup

  • 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);
        }
      });
    });