Support

Account

Home Forums Backend Issues (wp-admin) Select field content dependending from previous field

Solved

Select field content dependending from previous field

  • Hey folks,

    I need help with an issue that need to be done as close as possible to the standard acf features:

    Suppose that some content requires presets. However, these contents are so many in the sum that I can not specify these firmly. So I want to create an initial field in the input mask of the user, which is filled by this. After that, other fields should be filled with the previous entries.

    I had thought of something like this:

    • Multi-line input field => one attribute per line
    • Later in a flexible content, there are select fields (attribute_name). Each should be filled with options from the Multi-line input field (per line from the multi-line input field = an option in specific select field.)

    I tried to realize this by a custom admin.js, but the 'load_field/name=attribute_name' hook is not working:

        acf.add_action('load_field/name=attribute_name', function( $el ){
            console.log('select field loaded');
        });

    I would be very grateful for any assistance

    Pascal

  • And again, I solved it on my own ^^.
    I ended up with simple input fields.

    If anyone is interested in it, here is my admin.js code and a screencast gif:

    (function($){
        'use strict';
        acf.add_action('append', function( $el ){
            var layout = $el.attr('data-layout');
            if( layout === null || typeof layout === 'undefined') return;
            if( layout && layout.indexOf('_product') === -1 ) return;
    
            var $productAttributes = acf.get_field('', jQuery('.values [data-name="product_attributes"]'));
            var attributes = $productAttributes.find('textarea').val();
    
            $.each( attributes.split(/\n/),  function ( i, attr ) {
                $el.find('a[data-event="add-row"]').last().trigger('click');
                var name_input = $el.find('tr.acf-row:not(.acf-clone) [data-name="attribute_name"] input');
                name_input.last().val(attr);
                //name_input.prop('disabled', true); //not storing in db
            });
    
        });
    })(jQuery);

    Screencast

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

The topic ‘Select field content dependending from previous field’ is closed to new replies.