Skip to content

Fix bug text character length validation should be more helpful #1060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: v1/contrib
Choose a base branch
from

Conversation

NguyenThuyLan
Copy link
Contributor

Description

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

After fix:
image
image

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1060.westeurope.azurestaticapps.net

@nielslyngsoe nielslyngsoe marked this pull request as draft April 14, 2025 06:31
@nielslyngsoe
Copy link
Member

nielslyngsoe commented Apr 14, 2025

Hi @NguyenThuyLan. It's great to see some problem solving. I'm thought concerned about replicating any of our Localization Argument handling in UI Library. The Localization In the CMS both supports {0} and %0% and JS Methods

(arg0, arg1) => '...'

In general it is dangerous to have one system assuming support of another, in this case CMS sending in Localization Strings to the UI Library assuming that UI Library supports the same.

Instead we should implement this in a way that enables the CMS to be the sole owner of the Localization mechanism, and we can do so by using the technique I described on another PR:
#1069

Practically, it will look like this:

@property({ type: String, attribute: 'maxlength-message' })
maxlengthMessage: string | (max, current) => string = () => `Maximum ${max} characters, §{current} too many.`};
this.addValidator(
      'tooLong',
      () => {
        const label = this.maxlength;
        if (typeof label === 'function') {
            return label(this.maxlength, String(this.value).length);
        }
        return label;
      }
      () => !!this.maxlength && String(this.value).length > this.maxlength,
    );

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1060.westeurope.azurestaticapps.net

Copy link

Azure Static Web Apps: Your stage site is ready! Visit it here: https://delightful-beach-055ecb503-1060.westeurope.azurestaticapps.net

@nielslyngsoe nielslyngsoe marked this pull request as ready for review April 14, 2025 08:47
@Copilot Copilot bot review requested due to automatic review settings April 14, 2025 08:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@nielslyngsoe
Copy link
Member

apporach looks good, so I marked it as ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants