Skip to content

Commit

Permalink
Update setValue method
Browse files Browse the repository at this point in the history
  • Loading branch information
carry0987 committed Feb 24, 2024
1 parent b48bcb3 commit df0d138
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions dist/radioBox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ declare class RadioBox {
set onChange(callback: OnChangeCallback);
/**
* Set value of the checked radio box
* @param {string} value - Value to set
* @param {string | number} value - Value to set
*/
set value(value: string);
set value(value: string | number);
/**
* Get all radio box elements
* @return {RadioInputElement[]} All radio box elements
Expand All @@ -53,7 +53,7 @@ declare class RadioBox {
* @return {string} Value of the checked radio box
*/
get value(): string | null;
setValue(value: string): void;
setValue(value: number | string): void;
setChecked(index: number | string): void;
empty(): RadioBox;
refresh(): void;
Expand Down
7 changes: 4 additions & 3 deletions dist/radioBox.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ styleInject(css_248z);

class RadioBox {
static instances = [];
static version = '2.0.6';
static version = '2.0.7';
static firstLoad = true;
element = null;
options = defaults;
Expand Down Expand Up @@ -459,7 +459,7 @@ class RadioBox {
}
/**
* Set value of the checked radio box
* @param {string} value - Value to set
* @param {string | number} value - Value to set
*/
set value(value) {
this.setValue(value);
Expand All @@ -480,8 +480,9 @@ class RadioBox {
return checkedRadio ? checkedRadio.value : null;
}
setValue(value) {
value = value.toString();
this.allElement.forEach((element) => {
const shouldBeChecked = (typeof value === 'string' && element.value === value);
const shouldBeChecked = element.value === value;
if (shouldBeChecked && !element.checked) {
element.checked = true;
this.radioBoxChange(element);
Expand Down
2 changes: 1 addition & 1 deletion dist/radioBox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@carry0987/radio-box",
"version": "2.0.6",
"version": "2.0.7",
"description": "A library for create radio type check box",
"type": "module",
"main": "dist/radioBox.min.js",
Expand Down
9 changes: 5 additions & 4 deletions src/radioBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ class RadioBox {

/**
* Set value of the checked radio box
* @param {string} value - Value to set
* @param {string | number} value - Value to set
*/
public set value(value: string) {
public set value(value: string | number) {
this.setValue(value);
}

Expand All @@ -182,9 +182,10 @@ class RadioBox {
return checkedRadio ? checkedRadio.value : null;
}

public setValue(value: string): void {
public setValue(value: number | string): void {
value = value.toString();
this.allElement.forEach((element) => {
const shouldBeChecked = (typeof value === 'string' && element.value === value);
const shouldBeChecked = element.value === value;
if (shouldBeChecked && !element.checked) {
element.checked = true;
this.radioBoxChange(element);
Expand Down

0 comments on commit df0d138

Please sign in to comment.