Support

Account

Home Forums Add-ons Flexible Content Field Directly open layout if its single option?

Solved

Directly open layout if its single option?

  • I really love your flexible field system. I start to explore it new so if i am missing something, sorry for trouble ^^

    If i have only 1 layout option in flexible field, is it possible to open it directly when user click “add new row”?

  • If you only have one layout option you should use the repeater-field instead since that’s pretty much exactly what it is 🙂

    It’s also an easier setup and easier to output!

  • God.. i clicked solved accidently..

    Well, I dont have repeater addon.

  • Okay,

    Then to answer your question no, you cant have the one layout be chosen per default when adding a flexible field.. Since it would be pretty much the same as repeaterfield except less effective. I strongly suggest that if this is an issue for you just purchase the repeater field addon 🙂 Trust me, it’s well worth it!

  • I bought options & flexible this week and probably i will buy gallery and repeater soon but i would rather make this section with flexible field because i will probably add new layouts there in future. I was just asking if its possible to open directly single one

  • Hi @unsalkorkmaz

    Interesting… so if there is only 1 layout option, just add it instead of showing the selection?

    I’ll be sure to add this into the next version

    Thanks
    E

  • God.. these forum’s wysiwysg is buggy. When you you try to add link to a string, it closes window! I wrote a long descripton but its gone because of that -.-‘

    Anyway..

    It was for map markers. I want users add multi markers if they want. In future, i will try to support advanced additions like interactive map: http://leafletjs.com/examples/choropleth.html or vectors maybe: http://leafletjs.com/examples/quick-start.html Thats why i have to use flexible content for markers but it has to be 1 option for now.

  • Hello,

    I know the topic is kind of old, but I decided to dig in and found the following solution:

    
    add_action('acf/input/admin_footer', 'hwk_flexible_content_layout_no_popup');
    function hwk_flexible_content_layout_no_popup() {
        ?>
        <script type="text/javascript">
        jQuery(document).ready(function($){
            
            // ACF Flexible Content: Directly add layout if there's only one layout
            var flexible_content_open = acf.fields.flexible_content._open;
            acf.fields.flexible_content._open = function(e){
                
                var $popup = $(this.$el.children('.tmpl-popup').html());
                
                // Count layouts
                if($popup.find('a').length == 1){
                    acf.fields.flexible_content.add($popup.find('a').attr('data-layout'));
                    return false;
                }
                
                // More than one layout? Continue the JS execution
                return flexible_content_open.apply(this, arguments);
            }
        });
        </script>
        <?php
    }
    

    Hope it helps 🙂

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

The topic ‘Directly open layout if its single option?’ is closed to new replies.