Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with double digit numbers in multiple select #115

Closed
systemshock89 opened this issue Aug 17, 2023 · 11 comments · Fixed by #118 or #119
Closed

Problem with double digit numbers in multiple select #115

systemshock89 opened this issue Aug 17, 2023 · 11 comments · Fixed by #118 or #119
Labels
bug Something isn't working

Comments

@systemshock89
Copy link

systemshock89 commented Aug 17, 2023

Hi.
If there are two-digit numbers in multiple selects (example https://ghiscoding.github.io/multiple-select-vanilla/#/example03), then when I select the value 15, the Select has the value 1, 5, 15 (but I only selected 15).

Please fix this bug

@ghiscoding
Copy link
Owner

it does not on my side
image

@systemshock89
Copy link
Author

systemshock89 commented Aug 17, 2023

Sorry, maybe I'm not explaining it accurately, but

  1. I select in "basic select" number 15.
    2023-08-17_16-40-03

  2. Then I check the value in this select with this function

function getSelectValues(select) {
  var result = [];
  var options = select && select.options;
  var opt;

  for (var i=0, iLen=options.length; i<iLen; i++) {
    opt = options[i];

    if (opt.selected) {
      result.push(opt.value || opt.text);
    }
  }
  return result;
}

 alert(getSelectValues(document.querySelector('select')));
  1. I get the numbers 1, 5, 15 instead of the number 15 that I actually selected
    2023-08-17_16-41-06

When using native multiple select everything works correctly - I get the number 15 if I select 15.
It does not work correctly when using this plugin

@ghiscoding
Copy link
Owner

ghiscoding commented Aug 17, 2023

Pull Request is welcome if you find how to fix it, but why don't you use getSelects() method instead? do you get the same result? I doubt it and I'm too busy at the moment to look at this

setSelects / getSelects

Also note that I didn't create this library and I always use getSelects for my own usage, I also do not see this issue being reported on the original library multiple-select (jQuery)

@systemshock89
Copy link
Author

The getSelects() method gives the same result as my function.
In "Group Select" on the page https://ghiscoding.github.io/multiple-select-vanilla/#/example03, I selected a value of '11'.
Then using multipleSelect('select')[1].getSelects() I got ['1', '11'] instead of [11']

In the "Multiple Select with Jquery" plugin, it works correctly:
On the page https://multiple-select.wenzhixin.net.cn/templates/template.html?v=701&url=multiple-items.html in "Group Select" I select 11 and using $('select').multipleSelect('getSelects') I get ['11']

I think the problem is in the "Multiple Select on js" plugin.
Ok, I'll use another plugin.

@ghiscoding
Copy link
Owner

It would be better if you could help to find the problem instead of just changing library

@ghiscoding
Copy link
Owner

ghiscoding commented Aug 22, 2023

found the problem to be that the comparison was done via a substring check instead of a full string value check. However please note that I was able to reproduce the error with the code you provided but I was not able to reproduce with the .getSelects(); which is the method I always use which is probably why I did not catch the problem.

fixed and released in v0.4.8

@systemshock89
Copy link
Author

Thanks!
But now there is a new problem: I can't unckeckecked selected checkboxes in multipleSelect.
(unckeckecked values will be present in the array using the .getSelects() method)

In the "Multiple Select with Jquery" plugin, it works correctly.

@ghiscoding
Copy link
Owner

ghiscoding commented Aug 22, 2023

I pushed a new version, I found a regression bug right after the release (the same bug you found I think), you can test v0.4.9 instead, it should be fixed now. You can test it by trying Example - Form Data and clicking the Submit button, then uncheck and check other options and click Submit again, now it's ok. I also added new E2E tests to cover this new issue

@systemshock89
Copy link
Author

It works! Thank you very match!

@ghiscoding
Copy link
Owner

you can upvote the lib if it's helpful ⭐

bye now

@systemshock89
Copy link
Author

I already voted.
Bye

@ghiscoding ghiscoding added the bug Something isn't working label Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants