sergiodlopes/jquery-flexdatalist

Intentionally duplicate values returning only 1 of 2 values (solution provided)

andrewM202 opened this issue · 3 comments

Hello,

I have not contributed to any open source project before, so my apologies if I breach any formalities! This issue may not be reproducible, in which case it should be ignored. I am using this flexdatalist plugin with Svelte and jquery, and because of this I had to slightly modify the library - change all the $ selectors to j$ selectors as Svelte throws an error as $ is built in.

Nevertheless, I have a flexlist input where the "allowDuplicateValues" option is set to true. However, when I serialize() the input, I noticed that even though the flexlist allows me to add duplicate values, the serialize() jquery method does not pick up the duplicates and only one of the duplicates is actually sent to the server as a consequence.

As an example, I will add the duplicate values "text" to the input, but when I serialize it, I get the result: 'input=text', instead of 'input=text%2Ctext'

I was looking into the source code for jquery.flexdatalist.min.js, and I noticed that in the "push" section of the code, there is the following line:

if (a.includes(e)) return !1;

After debugging, I noticed that this seemingly checks if an array of values already has a value, and if it does, it will not add it to the array of values. I added a slight change to see if the "allowDuplicateValues" option is also set to true by calling the isDup() function, and now the form is picking up the duplicate values when I serialize it

if (a.includes(e) && i.isDup(e)) return !1;

Here is the whole section of code from jquery.min.js (auto-linted for clarity) for reference, with my change in it. If more examples are needed, or if my issue is poorly done, please let me know for the next time I make one! Thanks!

push: function (e, t) {
var a = i.fvalue.get();
if (a.includes(e) && i.isDup(e)) return !1;
(e = i.fvalue.toObj(e)),
a.push(e),
(e = i.fvalue.toStr(a)),
(i.value = e);
},

Hi Andrew,

I am experiencing same issue. I couldn't find above code parts you are mentioning. Would you upload the file?

Much appreciated. Big Thanks!

Hey tony, no problem. Attached is my file with a comment right next to my fix:
// Here is my ad hoc fix, adding i.isDup(e)
Hopefully this helps! So you are aware, I had to change the file to a .txt for GitHub to allow me to upload it, but you can just change it back to a .js when you download it.
jquery.flexdatalist.txt

thank you!