Skip to content

Commit

Permalink
don't error when no primary buttons in form
Browse files Browse the repository at this point in the history
  • Loading branch information
fergusean committed Aug 19, 2023
1 parent ee82d2d commit a35b7a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@signal24/vue-foundation",
"type": "module",
"version": "4.7.2",
"version": "4.7.3",
"description": "Common components, directives, and helpers for Vue 3 apps",
"module": "./dist/vue-foundation.es.js",
"bin": {
Expand Down
22 changes: 14 additions & 8 deletions src/helpers/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const FormMaskState = Symbol('FormMaskState');
interface IFormMaskState {
[FormMaskState]?: {
disabledElements: HTMLElement[];
waitButton: HTMLElement;
buttonHtml: string;
waitButton?: HTMLElement;
buttonHtml?: string;
};
}
type FormMaskElement = Element & IFormMaskState;
Expand All @@ -62,10 +62,13 @@ export function maskForm(formOrCmp: Element | AnyComponentPublicInstance, button

const buttonEl = (
buttonSelector instanceof Element ? buttonSelector : form.querySelectorAll(buttonSelector ?? 'button:not([disabled]):not([type="button"])')[0]
) as HTMLElement;
const originalButtonHtml = buttonEl.tagName === 'INPUT' ? (buttonEl as HTMLInputElement).value : buttonEl.innerHTML;
buttonEl.setAttribute('disabled', 'disabled');
buttonEl.innerText = buttonText ?? 'Please wait...';
) as HTMLElement | undefined;
let originalButtonHtml: string | undefined;
if (buttonEl) {
originalButtonHtml = buttonEl.tagName === 'INPUT' ? (buttonEl as HTMLInputElement).value : buttonEl.innerHTML;
buttonEl.setAttribute('disabled', 'disabled');
buttonEl.innerText = buttonText ?? 'Please wait...';
}

const inputsQR = form.querySelectorAll('input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled])');
const inputs = [...inputsQR] as HTMLElement[];
Expand All @@ -89,8 +92,11 @@ export function unmaskForm(formOrCmp: Element | AnyComponentPublicInstance) {
form.classList.remove('vf-masked');

state.disabledElements.forEach(el => el.removeAttribute('disabled'));
state.waitButton.innerHTML = state.buttonHtml;
state.waitButton.removeAttribute('disabled');

if (state.waitButton) {
state.waitButton.innerHTML = state.buttonHtml!;
state.waitButton.removeAttribute('disabled');
}

delete (form as FormMaskElement)[FormMaskState];
}
Expand Down

0 comments on commit a35b7a0

Please sign in to comment.