Open Lefthandmedia opened 4 years ago
Hi @Lefthandmedia, thanks for the question.
The toggle was never made to work with arrays. Basically, it looks to the URL and if the value is equal to what you send, it removes it. If the value is not equal to what you send, it adds it.
Aa a workaround, you could use set
, but I understand that it is not as convenient.
qsm('https://www.google.cz/search?q=hello+world&num=20&num=40&num=60', {
set: {
num: [20,60],
}
});
Introducing such functionality would be a breaking change and I'm not sure it would be straightforward enough, beacuse we would be treating two values with different behaviour.
What do you think?
I think that when it is possible to add values as an array a remove method for 1 value should also exist. I see a discussion at whatwg going on on the same topic. https://github.com/whatwg/url/issues/335 But until that time URLsearchparams will incorporate this i think it would be a usefull addition to Qsm. instead of Qsm.delete(),as suggested in the Whatwg discussion, i would opt for a Qsm.remove() method so not to confuse the standard delete functionality from URLsearchParams. So Qsm.remove({"key":"value"}), just my thoughts RDG
I cant get the toggle function to work. first i set a few params with:
then i try to remove one of the with: qsm('https://www.google.cz/search?q=hello+world&num=20', { toggle: { num: 40, } });
then the all other params 'num' are gone.
Can it be that the function
toggleParams
is not returning anything? looks like it should returnurlParamsNext
Im using the NPM versionRDG