I have a screen which contains a repeater and a few fields. A user can select a post from the select dropdown which uses the post object. I am after a way to removing the item from a select dropdown once it has been selected. The issue is, if you’re selecting posts, you can keep on selecting the same post over and over again.
Ideally, the other post fields would filter based on the previous select options before those fields. Is there a clean and easy way to do this?
This would be possible, but not easy and I do not know of any examples. It would require adding custom JavaScript. And altering all of the AJAX queries for the post object fields based on the selection of other fields.
I would likely go with dynamically populated select fields rather than a built in relationship field and do my own AJAX requests in order to get available values based o the selections made in the other rows.
This is my solution for this:
Add this to execute a particular script:
add_action('acf/input/admin_footer', array($this, 'filter_results'));
public function acf_filter_products_selection() {
?>
<script type="text/javascript">
(function($) {
acf.add_action('ready', function( $el ){
acf.add_filter('select2_ajax_results', function( json, params, instance ){
//Do whatever you want with the json.results array that contains the
//results from the DB
return json;
});
});
})(jQuery);
</script>
<?php
}