feat: add mask() method to input field components for masking library integration#161
Draft
feat: add mask() method to input field components for masking library integration#161
Conversation
… integration - Add mask(callback) method to SmarkField (via input.type.js): - Changes <input> type to "text" for non-text inputs (required by iMask.js etc.) - Stores original type in _originalType for reference - Calls callback(targetFieldNode) and stores result as _maskInstance - Delegates to inner field for singletons, returns `me` for chaining - Update _setTargetFieldValue() to dispatch "input" event when mask is active, so masking libraries re-process the new value on programmatic import() - Update export() to use _maskInstance.unmaskedValue when available, so derived types (number, date, etc.) still parse/return the correct semantic type - Add comprehensive tests in test/mask.tests.js (13 scenarios) Agent-Logs-Url: https://github.com/bitifet/SmarkForm/sessions/72c9bcc2-72c5-42a0-8d32-9fe27015b3da Co-authored-by: bitifet <1643647+bitifet@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
bitifet
April 17, 2026 23:21
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a public
.mask(callback)method to SmarkForm field components that provides a clean integration scaffold for input-masking libraries (like iMask.js) without adding any hard dependency.Changes
src/types/input.type.jsmask(callback)method (added to theinputclass, inherited bynumber,date,time,datetime-local,color, etc.):<input type>to"text"for any non-text input, because masking libraries like iMask.js requiretype="text". The original type is preserved in_originalType.callback(targetFieldNode)with the raw DOM element as the sole argument — this is the integration point where the caller attaches iMask or any other library._maskInstance._maskInstancelives whereexport()reads it).thisfor chaining._setTargetFieldValue()updated:inputevent on the element when a mask instance is active. This allows masking libraries to re-process the value whenimport()is called programmatically.export()updated:_maskInstance.unmaskedValueis defined, uses it as the raw value instead ofnodeFld.value. This ensures that derived types (number,date,time, etc.) receive the raw unmasked string and can still apply their own semantic type conversion (e.g.Number("1234.56")→1234.56rather thanNumber("1,234.56")→NaN).test/mask.tests.js(new)13 Playwright test cases covering:
_originalTypeis stored correctlymask()returnsthisfor chainingexport()usesunmaskedValuewhen providednumberafter maskingnodeFld.valuewhen mask has nounmaskedValue(or returns null)_maskInstancelands on the inner fieldimport()dispatchesinputevent on masked fields (and does NOT dispatch it on unmasked fields)Usage example (iMask.js)
Testing
All 284 existing tests continue to pass. All 13 new mask tests pass.