Support

Account

Home Forums ACF PRO ACF PRO: Make custom field available for conditional logic

Solved

ACF PRO: Make custom field available for conditional logic

  • Hi,

    I’m playing around with creating a new custom field for test purposes. It’s pretty much a clone of the radio field. But, i’m having some trouble to figure out how to make the field available for other fields in conditional logic. I’m getting: “No toggle fields available”.

    See current class:
    https://gist.github.com/anonymous/726ef3a080bf43b52cc5

    I haven’t been able to find any documentation on this subject, so i’m curious on how to implement this logic.

  • Okay, i got it. But it was rather tricky.

    To be able to inherit the conditional logic you field has to have either of these name: select, checkbox or radio.

    But since that these fields already exists, we’re aren’t to use the conditional logic.

    This lives in the field-group.js file (which is minified to field-group.min.js).

    Okay, so far so good. We can’t do anything to make our custom fields use the conditional logic – without hacking.

    My solution endend up with this small javascript piece which i inject to the edit page (for the custom fields not the post):

    
    ;(function($){
        var myFieldName = 'my-field';
    
        $(document).ready(function () {
            $(document)
            .find('[data-type="'+ myFieldName +'"]')
            .attr('data-type', 'radio');
        });
    })(jQuery);
    

    This “hack” changes the field type to a radio which makes it available for the conditional logic.

    I definitely think that this should be change in ACF, it’s just silly that we have to make these kind of hackes to make it work..

    Hope it helps some one else.

  • Thanks for your solution. For ACF PRO v5.3.2.2 it should be:

    ;(function($){
        var myFieldName = 'my-field';
    
        $(document).ready(function () {
            $(document)
            .find('[data-type="'+ myFieldName +'"]')
            .data('type', 'radio'); // here is the change
        });
    })(jQuery);
  • Hmm, assets/acf-input.js

    Line(s) 9700, 9920 and other fieldtype lines … Add manually add it the custom field type there.

    I am wondering if there a way to add the custom field type to the array on runtime??

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

The topic ‘ACF PRO: Make custom field available for conditional logic’ is closed to new replies.