Choices icon indicating copy to clipboard operation
Choices copied to clipboard

'search_terms' in POST data

Open divan opened this issue 3 years ago • 11 comments

Describe the bug When choices.js is used in the form, it submits also data for search_terms.

To Reproduce Steps to reproduce the behavior:

  1. Create demo form with choices input (without disabling search)
  2. Submit data
  3. Check payload in Dev Tools or on server
  4. See search_terms in the post data

Expected behavior No "search_terms" value got to the form.

divan avatar Aug 05 '22 21:08 divan

This was particularly frustrating as the name of my input was previously 'search_terms', so was being overridden. Re-naming fixes it, but still the unwanted post data is there.

michaellatham avatar Aug 31 '22 16:08 michaellatham

I have an issue with search_terms naming too, but with GET. In my scenario, I have 7 multiselect fields with choices.js which work as grid filters which has to work in GET (there are a few reasons to prefer this to POST). This means that when I trigger the search via clicking the search button, I end up having 7 &search_terms= concatenated in the query string.

I tried to completely remove the name attribute from the compiled choice.js input, and this way the query string is obviously correct. From what I can tell, the solution could be to do exactly that (although I know it would be "bad" html5; https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#name), even if in my opinion those fields should not be included in the form since their job is merely to make the js code work (which does not rely on that attribute), from the point of view of the request.

Any considerations about this matter?

masiorama avatar Oct 07 '22 06:10 masiorama

Did anybody find a solution about this?

masiorama avatar Nov 18 '22 09:11 masiorama

Sorry to bother again but I would like to know if this could be fixed somehow (I could make a pull request but I would like to discuss which is the best way to solve it without breaking anything).

masiorama avatar Dec 29 '22 07:12 masiorama

I got the same issue. It looks like a regression since release 10. Downgrading to 9.1.0 fix the issue for me.

Guzzii avatar Feb 26 '23 23:02 Guzzii

Also having this issue. For php name can be set to empty string and will be ignored:

callbackOnInit: () => {document.getElementsByName('search_terms')[0].name = '';}

Not very helpful if you already have one on the page though, config to disable this would be nice.

boccoadam avatar Apr 03 '23 20:04 boccoadam

Up please

joffreypersia avatar Apr 20 '23 15:04 joffreypersia

up

lavgl avatar Jul 10 '23 11:07 lavgl

Fwiw, this caused all sorts of problems on a few sites of mine after updating. It took me quite a while to figure out where this new search_terms POST/GET var was coming from. I also rolled back to version 9.

natebeaty avatar Nov 26 '23 18:11 natebeaty

As another option:

callbackOnInit: function () {
  this.input.element.name = ''
}

bupy7 avatar Jan 20 '24 20:01 bupy7

Definitely a +1 in terms of this being purged from the form data, or at least made optional.

It also breaks if there's multiple Choices.js instances active within the same form, as they each use search_terms, so the name should be configurable if it's enabled.

middaparka avatar Feb 07 '24 13:02 middaparka