Skip to content

Instantly share code, notes, and snippets.

@mouse0270
Created January 12, 2025 17:33
Show Gist options
  • Save mouse0270/3e413e24cf5fb4c906f6dd10e80a64df to your computer and use it in GitHub Desktop.
Save mouse0270/3e413e24cf5fb4c906f6dd10e80a64df to your computer and use it in GitHub Desktop.
MudBlazor JS Masking using Inputmask.ks
/**
* Retrieves an HTML element by its ID.
*
* @param {string} id - The ID of the element to retrieve.
* @param {object} mask - The mask to apply to the element.
*/
window.MASK = function (id, mask) {
// Get the element by its ID
const element = document.getElementById(id);
// Check if the element exists
if (!element) return;
// Check if the element already has an InputMask applied
if (element.inputmask) return;
// Attempt to mask the element, if it fails try again after a delay
try {
// Apply the mask to the element
Inputmask(mask).mask(element);
} catch (error) {
// Masking failed, try again if there are tries left, adjust the tries by -1
console.error('Masking failed for element:', element, 'Error:', error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment