Hi @magicpriest ,
Thank you for the kind words!
> I’m wondering is there any way to load data as select field value through ajax or any other way
Currently, such functionality is not supported in core but if you are familiar with React you could write your own extension field for this purpose (https://carbonfields.net/docs/extending-extending/?crb_version=2-0-0).
If you are looking for a quick and dirty solution, you could hack in a simple select using jQuery which updates its options when a field’s value changes by utilizing the appropriate event in the JavaScript API (https://carbonfields.net/docs/advanced-topics-javascript-api/?crb_version=2-0-0) but you’ll have to handle it’s own data saving and loading.
Hi @atanasangelovdev ,
Thank you for fast reply.
I’m here just to say thank you for your work and provide some thoughts during this work.
So, the way I have chosen is constructing data and Fields. The idea is simple, first of all get what you need (for me it CustomPostType terms and posts which belongs to certain term and pack it in way you like), then construct arrays of fields, for example:
$fieldConstructor[] =
Field::make( 'select', $term['term_slug'], $term['term_name'] )
->add_options( $term['term_posts'] )
And then add conditional logic in your construction. It’s so awesome, to have all things in one place and manipulating data without annoyance.
The last thing, is opinion of Devs of this library. Is this dirty or aboutToBeDirty hack?
I’m not exactly sure what you are doing exactly but keep in mind that conditionally created fields will be created conditionally when a user visits the site as well (not only for admin requests) and you cannot get a field’s value if the field has not been defined for the current request (2.0+).