Support

Account

Home Forums ACF PRO Loading data inside a custom field type

Helping

Loading data inside a custom field type

  • I am creating a custom filed type, essentially an extension of the select field type, which will render using select2. IN that it is pretty straightforward, however I wish to load the choices using an ajax query, but I want to keep all the code encapsulated inside the field type, rather than have an additional filter in functions.php to load the choices.

    basically I don’t want to have to add anything specific to handle this field outside of the field type itself. So that I can disable the options in the select and have it simply work when dropped into the cms

  • So add your ajax action directly in the field class. For an example of this see any of the built in ACF relationship type fields. All of these use Select2 and are dynamically populated via AJAX.

    Maybe you misssed it by the ACF select field has an option to do this already.

    Presentation => Stylized UI
    when turned on there is a second option to => Use Ajax to lazy load choices.

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

You must be logged in to reply to this topic.