Home › Forums › Autocomplete › Callback for removing multi-selection AC
- This topic has 6 replies, 2 voices, and was last updated 3 years, 2 months ago by Alexander Bautz.
-
AuthorPosts
-
-
September 3, 2021 at 05:38 #34396
I saw there was a callback created for entering a value in the ac, but was curious if there exists a callback or a way to set up an onChange event for when the user removes a selected ac option from a multi-select ac?
I was going to create a setField originally but noticed that doesn’t work for multi-select ac configurations. Then I noticed the callback and thought I could potentially create what I need by querying the list and re-populating the desired field needed to be set but have it comma separated in the same order as the ac selections. If I just had a way to trigger the repopulate on selection removal tied with the existing selection callback it should be all I need.
-
September 3, 2021 at 15:59 #34403
There is no callback you can use directly, but removing an item from an autocomplete will trigger any “on change rules” you configure on the field in DFFS. Try setting up a rule that triggers on change and then have this rule call a custom function in your Custom JS where you add your code.
Alternatively you can add an onclick event like this:
jQuery("#dffs_YourFieldName").on("mouseup", ".spjs_ac_multi_removeSelected", function(){ // An item has been removed });
Replace YourFieldName with your actual field name.
Alexander
-
September 3, 2021 at 19:30 #34405
I like that! I appreciate it?
-
-
September 9, 2021 at 00:25 #34452
Ah dang the mouse up is close but still returns the removed item using SetFieldValue. I tried “change” and that didn’t work either. I tried to create a rule but since my ac field is actually a multi-line plain text field I don’t think I can create a rule on that.
- This reply was modified 3 years, 2 months ago by Jonathan Stamper.
-
September 9, 2021 at 15:36 #34457
Try setting a delay so the code that removes it have time to complete before your custom code triggers:
jQuery("#dffs_YourFieldName").on("mouseup", ".spjs_ac_multi_removeSelected", function(){ setTimeout(function(){ // Add your custom code here },500); });
This will delay it 500ms – see if that helps.
Alexander
-
September 9, 2021 at 22:09 #34469
That was it! Just needed some time before executing. I even included a 3rd option to catch the mouse up event on the spjs_acItem class to continue appending the field next to it as the user starts clicking items all in one go.
Though it’s a rough/ugly way of setting other fields using multi-select ac it works great!
-
September 10, 2021 at 15:38 #34477
Thanks for the update – I’m glad you got it up and running.
Alexander
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.