Skip to content

Commit

Permalink
feat: AutoSubmitFormController - Change eventModeValue to support mul…
Browse files Browse the repository at this point in the history
…tiple events. Backwards compatible with old syntax.
  • Loading branch information
Sub-Xaero committed Dec 15, 2021
1 parent e04dbd7 commit efaa124
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/controllers/forms/auto_submit_form_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ export class AutoSubmitFormController extends BaseController {
declare debounceIntervalValue: number;
declare readonly hasDebounceIntervalValue: boolean;

get _eventMode(): 'change' | 'input' | 'debounced' {
get _eventModes(): Array<'change' | 'input'> {
if (this.hasEventModeValue) {
if (!['change', 'input', 'debounced'].includes(this.eventModeValue)) {
let modes = this.eventModeValue.split(' ').map(mode => mode.trim());

if (modes.length === 1 && modes[0] === 'debounced') {
return ['change', 'input'];
}

if (!modes.every(mode => ['change', 'input'].includes(mode))) {
throw new Error(`The modeValue provided '${this.eventModeValue}' is not one of the recognised configuration options`);
}
return this.eventModeValue;

return modes as Array<'change' | 'input'>;
} else {
return "change";
return ["change"];
}
}

Expand Down Expand Up @@ -53,7 +60,7 @@ export class AutoSubmitFormController extends BaseController {
return useEventListener(
this,
el as HTMLElement,
this._eventMode == 'change' ? 'change' : 'input',
this._eventModes,
this.submit,
{debounce: this._eventMode == 'debounced' ? this._debounceTimeout : undefined},
);
Expand Down

0 comments on commit efaa124

Please sign in to comment.