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

Added option to reset() method to control the change event trigger #322

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/assets/virtual-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -3200,12 +3200,14 @@ var VirtualSelect = /*#__PURE__*/function () {
key: "reset",
value: function reset() {
var formReset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var disableChangeEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
this.options.forEach(function (d) {
// eslint-disable-next-line no-param-reassign
d.isSelected = false;
});
this.beforeValueSet(true);
this.setValue(null, {
disableEvent: disableChangeEvent,
disableValidation: formReset
});
this.afterValueSet();
Expand Down Expand Up @@ -3607,7 +3609,9 @@ var VirtualSelect = /*#__PURE__*/function () {
}, {
key: "reset",
value: function reset() {
this.virtualSelect.reset();
var formReset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
var disableChangeEvent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
this.virtualSelect.reset(formReset, disableChangeEvent);
}
}, {
key: "setValueMethod",
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/virtual-select.min.js

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions docs/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ $('#sample-select').val();
**Arguments:**

- value - single value or array of values
- disableEvent - set true to avoid event trigger
- disableValidation - set true to disable the validation
- disableEvent - set `true` to avoid event trigger
- disableValidation - set `true` to disable the validation

```js
var value = 3; /** for single select */
Expand All @@ -48,6 +48,11 @@ document.querySelector('#sample-select').setValue(value);

### reset()

**Arguments:**

- formReset - set `true` to disable validations
- disableChangeEvent - set `true` disable the change event

```js
document.querySelector('#sample-select').reset();
```
Expand All @@ -57,7 +62,7 @@ document.querySelector('#sample-select').reset();
**Arguments:**

- options - list of options details
- keepValue - set true to keep selected value
- keepValue - set `true` to keep selected value

```js
var options = [
Expand Down Expand Up @@ -90,7 +95,7 @@ document.querySelector('#sample-select').setDisabledOptions(true);
**Arguments:**

- enabledOptions - list of enabled option's values or `true` to enable all options
- keepValue - set true to keep selected value
- keepValue - set `true` to keep selected value

```js
var enabledOptions = [2, 6, 9];
Expand Down
8 changes: 4 additions & 4 deletions src/virtual-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -2861,14 +2861,14 @@ export class VirtualSelect {
}
}

reset(formReset = false) {
reset(formReset = false, disableChangeEvent = false) {
this.options.forEach((d) => {
// eslint-disable-next-line no-param-reassign
d.isSelected = false;
});

this.beforeValueSet(true);
this.setValue(null, { disableValidation: formReset });
this.setValue(null, { disableEvent: disableChangeEvent, disableValidation: formReset });
this.afterValueSet();

if (formReset) {
Expand Down Expand Up @@ -3306,8 +3306,8 @@ export class VirtualSelect {
return !hasError;
}

static reset() {
this.virtualSelect.reset();
static reset(formReset = false, disableChangeEvent = false) {
this.virtualSelect.reset(formReset, disableChangeEvent);
}

static setValueMethod(...params) {
Expand Down