Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add Input Mask Validation#993

Merged
JhumanJ merged 21 commits intomain-v2OpnForm/OpnForm:main-v2from
1fca6-text-input-maskOpnForm/OpnForm:1fca6-text-input-maskCopy head branch name to clipboard
Jan 6, 2026
Merged

Add Input Mask Validation#993
JhumanJ merged 21 commits intomain-v2OpnForm/OpnForm:main-v2from
1fca6-text-input-maskOpnForm/OpnForm:1fca6-text-input-maskCopy head branch name to clipboard

Conversation

@chiragchhatrala
Copy link
Copy Markdown
Collaborator

No description provided.

chiragchhatrala and others added 18 commits June 6, 2025 20:36
- Introduced a new `InputMaskRule` for validating input masks in form requests, enhancing data integrity for text fields.
- Updated `AnswerFormRequest` and `UserFormRequest` to include input mask validation rules, allowing for flexible input formats.
- Enhanced `TextInput` component to support input masks, improving user experience with formatted input fields.
- Added `useInputMask` composable for managing input mask logic, ensuring consistent behavior across components.
- Updated `FieldOptions` to allow configuration of input masks for text fields, providing users with more customization options.

These changes aim to improve form handling and user input validation, ensuring that data adheres to specified formats while enhancing the overall user experience in form interactions.
- Implemented a new method to validate input mask patterns, ensuring only allowed characters (a, 9, *, and common punctuation) are accepted.
- Updated the help text to clarify the format and provide examples for users, improving usability and guidance for input mask patterns.
- Updated regex patterns in UserFormRequest and InputMaskRule to improve input mask validation.
- Enhanced MaskInput component to utilize getUnmaskedValue for accurate character counting.
- Refactored useInputMask composable to correctly mark tokens as optional and validate mask patterns.
- Improved FieldOptions component by reintroducing input mask pattern help text and examples.

These changes enhance the functionality and user experience of input masks across the application.
- Improved InputMaskRule to handle optional mask tokens more effectively, allowing for better validation of input values.
- Updated error messages to escape mask patterns for XSS prevention.
- Enhanced MaskInput component to support pasting formatted values and maintain cursor position during input changes.
- Refactored useInputMask composable to streamline mask validation and formatting processes.

These changes improve the robustness and user experience of input masking across the application.
@JhumanJ
Copy link
Copy Markdown
Collaborator

JhumanJ commented Jan 3, 2026

@cursoragent expert PR review

Also resolve conflicts

@cursor
Copy link
Copy Markdown

cursor Bot commented Jan 3, 2026

View PR

The merge conflict is resolved and all changes are staged. Let me now provide the expert PR review:


Expert PR Review: Add Input Mask Validation

✅ Merge Conflict Resolution

I've resolved the merge conflict in api/app/Http/Requests/UserFormRequest.php. The conflict arose because main-v2 refactored form property validation from wildcard rules (properties.*) to a single-pass FormPropertiesRule for performance. I integrated the input_mask validation into the new TypePropertyValidator class instead of adding it as a wildcard rule.


🔍 Code Review Summary

Backend (PHP/Laravel)

1. InputMaskRule.php - ✅ Well Implemented

  • Clean validation logic with token-based mask parsing
  • Proper handling of optional tokens (? modifier)
  • XSS prevention by escaping mask patterns in error messages using htmlspecialchars()
  • Good separation of concerns: validateMaskPattern() and validateValueAgainstMask()

Minor Issues:

// Line 33: validateMaskPattern returns int|false, not bool
private function validateMaskPattern(string $mask): bool
{
    return preg_match('/^[9a*().\s\-?]*$/', $mask);  // Should cast to bool
}

Suggestion: Use (bool)preg_match(...) or preg_match(...) === 1

2. AnswerFormRequest.php - ✅ Correct Integration

  • Properly applies InputMaskRule only when input_mask is set on text fields
  • Good placement at line 204-206

3. TypePropertyValidator.php (my addition for conflict resolution)

  • Added input_mask validation pattern matching backend regex
  • Consistent with the new property validation architecture

Frontend (Vue/Nuxt)

1. MaskInput.vue - ⚠️ Good with Minor Issues

Strengths:

  • Properly uses the composable pattern with useInputMask
  • Good handling of paste events
  • Maintains cursor position during input changes
  • Proper accessibility with aria-label including format hint

Issues to Address:

// Line 94: isInternalUpdate is not reactive, potential race condition
let isInternalUpdate = false

Suggestion: Consider using ref(false) for consistency, though current approach should work

// Line 267: useFormInput called twice - potential bug
return {
  ...useFormInput(props, context, {...}),  // Second call

Issue: useFormInput is already called at line 82. Spreading it again creates duplicate state.

2. useInputMask.js - ✅ Well Implemented

  • Clean token-based parsing matching backend logic
  • Proper handling of optional characters
  • Good getDisplayValue() implementation for UX

3. BlockRenderer.vue - ✅ Correct Integration

else if (field.type === 'text' && field.input_mask) componentName = 'MaskInput'
// ...
else if(field.type === 'text' && field.input_mask) {
  inputProperties.mask = field.input_mask
  inputProperties.slotChar = field.slot_char
}

4. FieldOptions.vue - ✅ Good UI/UX

  • Uses popover for input mask configuration
  • Clear help text with format examples
  • Proper validation with onInputMaskChange() method
  • Crisp helpdesk article integration

Test Coverage - ✅ Comprehensive

The InputMaskRuleTest.php covers:

  • Basic phone format validation
  • All-digit masks
  • Mixed character masks
  • Optional character handling (multiple scenarios)
  • Edge cases (empty mask, only literals)

Suggestion: Add test for edge case where mask contains only ? at the start.


🏗️ Architecture Assessment

Aspect Rating Notes
Separation of Concerns ⭐⭐⭐⭐⭐ Frontend/backend logic mirrors correctly
Validation Consistency ⭐⭐⭐⭐ Same regex pattern on both ends
Error Handling ⭐⭐⭐⭐ Good error messages, XSS protected
Test Coverage ⭐⭐⭐⭐⭐ Comprehensive edge case testing
Performance ⭐⭐⭐⭐ Uses lazy-loaded component registry

🔧 Recommended Fixes (Optional)

  1. Fix duplicate useFormInput call in MaskInput.vue (lines 82 and 267)
  2. Cast preg_match to bool in InputMaskRule.php:33 for type safety
  3. Consider adding slot_char validation in TypePropertyValidator

✅ Verdict: Approve with Minor Suggestions

The PR implements a solid input mask feature with:

  • Proper validation on both frontend and backend
  • Good UX with visual feedback (slot characters)
  • Comprehensive test coverage
  • Correct integration with the component registry

The merge conflict has been resolved by integrating input_mask validation into the new TypePropertyValidator class following the main-v2 architecture.


Open in Cursor Open in Web

Learn more about Cursor Agents

cursoragent and others added 2 commits January 3, 2026 16:24
This commit introduces several improvements:

- **Analytics Integration:** Adds support for Meta Pixel, Google Analytics, and Google Tag Manager, allowing users to track form performance.
- **Submission Identifiers:** Migrates to UUIDs for submission IDs, enhancing security and performance. Legacy Hashid support is maintained for backward compatibility.
- **Partial Submissions:** Prevents completed submissions from being reverted to partial, addressing potential race conditions.
- **Admin Functionality:** Enables administrators to disable two-factor authentication for users.
- **Code Validation:** Implements robust validation for form properties and logic rules, improving data integrity.
- **Performance Optimizations:** Refactors form list endpoints to return lightweight data, reducing response size and improving load times.
- **UI/UX Enhancements:** Introduces a dedicated component for form analytics settings and improves the overall user experience.

Co-authored-by: julien <julien@nahum.net>
- Updated InputMaskRule to ensure proper boolean return type for mask pattern validation.
- Introduced 'slot_char' property in TypePropertyValidator for validating single character inputs, disallowing alphanumeric characters.
- Expanded InputMaskRuleTest to include tests for masks with only question marks, ensuring correct validation behavior.
- Refactored MaskInput component to improve handling of input and display values, including new methods for cursor management and character validation.

These changes improve the robustness of input masking and validation logic, enhancing user experience and data integrity.
@cursor
Copy link
Copy Markdown

cursor Bot commented Jan 6, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on February 23.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

…k Handling

- Updated MaskInput component to accept a function for slot character, enhancing flexibility in input masking.
- Replaced the UPopover component in FieldOptions with a new InputMaskOptions component, streamlining the UI and improving code organization.
- Removed redundant input mask change handling logic from FieldOptions, simplifying the component's setup.

These changes enhance the maintainability and usability of input masking features across the application.
@JhumanJ JhumanJ merged commit e8ae321 into main-v2 Jan 6, 2026
8 checks passed
@JhumanJ JhumanJ deleted the 1fca6-text-input-mask branch January 6, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.