bluzky / nice-select2

A lightweight vanilla javascript library that replaces native select elements with customizable dropdowns
https://bluzky.github.io/nice-select2/
MIT License
361 stars 60 forks source link

add instance.getValue() and instance.setValue(newVal) #88

Open amlan-sw opened 1 month ago

amlan-sw commented 1 month ago

instance.setValue(newVal)

//-- regular select
newVal = 'foo';

//-- selected foo and bar option for multiple
newVal = ['foo','bar']; 

source SELECT tag will also change its value and highlight following newVal

currentVal = instance.getValue()

Summary by Sourcery

Add methods to set and get the value of the select element, enhancing the functionality to support both single and multiple selections.

New Features:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request introduces two new methods, setValue and getValue, to the NiceSelect class. The setValue method allows for programmatically setting the value of the select element, while the getValue method retrieves the current value. Additionally, the handling of selected options has been improved in the _onItemClicked and resetSelectValue methods to ensure more robust manipulation of the 'selected' attribute.

File-Level Changes

Files Changes
src/js/nice-select2.js Enhanced the NiceSelect class with new methods for setting and getting the value of the select element, and improved the handling of selected options.

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.