Skip to content

Commit

Permalink
feat(js Element): Add blur, focus, clear, update methods
Browse files Browse the repository at this point in the history
Add extra methods for Element: blur, focus, clear, update.
Trigger extra events: ready, blur, focus.
  • Loading branch information
biinari committed May 7, 2021
1 parent dfac2b5 commit fd47d85
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions localstripe/localstripe-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class Element {
});

this._domChildren.forEach((child) => domElement.appendChild(child));
(this.listeners['ready'] || []).forEach(handler => handler());
}

unmount() {
Expand All @@ -213,6 +214,34 @@ class Element {
}
}

blur() {
Object.keys(this._inputs).forEach(field => {
this._inputs[field].blur();
});
(this.listeners['blur'] || []).forEach(handler => handler());
}

focus() {
var field = Object.keys(this._inputs)[0];
this._inputs[field].focus();
(this.listeners['focus'] || []).forEach(handler => handler());
}

clear() {
Object.keys(this._inputs).forEach(field => {
this._inputs[field].value = '';
});
}

update(options) {
if (!options) {
return;
}
if (options.value && options.value.postalCode && this._inputs.postal_code) {
this._inputs.postal_code.value = options.value.postalCode;
}
}

on(event, handler) {
this.listeners[event] = this.listeners[event] || [];
this.listeners[event].push(handler);
Expand Down

0 comments on commit fd47d85

Please sign in to comment.