Skip to content
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

[5.x] Fix helpBlock error with custom js validation rule #11023

Merged
merged 2 commits into from
Oct 29, 2024

Conversation

irfandumanx
Copy link
Contributor

I was encountering an error when using the example field while trying to extend rules this way in cp.js.

Statamic.booting(() => {
    Statamic.$config.set('extensionRules',
    [
        {
            label: 'Email Authenticator',
            value: 'email_authenticator:',
            example: 'email_authenticator:form'
        },
    ]);
});
TypeError: Cannot read properties of undefined (reading 'example')
    at q.helpBlock (app-4350e625.js:392:218858)
    at M.get (app-4350e625.js:5:42279)
    at M.evaluate (app-4350e625.js:5:43343)
    at q.helpBlock (app-4350e625.js:5:45757)
    at q.M (app-4350e625.js:392:221720)
    at M._render (app-4350e625.js:5:24987)
    at q.N (app-4350e625.js:5:29723)
    at M.get (app-4350e625.js:5:42279)
    at M.run (app-4350e625.js:5:43050)
    at flushSchedulerQueue (app-4350e625.js:5:32642)

TypeError: Cannot read properties of undefined (reading '$refs')
    at q.<anonymous> (app-4350e625.js:392:219887)
    at Array.<anonymous> (app-4350e625.js:5:39048)
    at flushCallbacks (app-4350e625.js:5:38224)

So i am submitting this PR because I've resolved this issue.

@irfandumanx irfandumanx changed the title Fixed issue of missing extension rule when using example feature in validation [5.x] Fixed issue of missing extension rule when using example feature in validation Oct 28, 2024
@jasonvarga
Copy link
Member

Thank you.

By the way, in your JS you are currently overriding everything. You should be merging the existing ones. Do this instead:

Statamic.booting(() => {
    Statamic.$config.set('extensionRules', [
        ...Statamic.$config.get('extensionRules'),
        {
            label: 'Email Authenticator',
            value: 'email_authenticator:',
            example: 'email_authenticator:form'
        },
    ]);
});

@jasonvarga jasonvarga changed the title [5.x] Fixed issue of missing extension rule when using example feature in validation [5.x] Fix helpBlock error with custom js validation rule Oct 29, 2024
@jasonvarga jasonvarga merged commit 7172e7a into statamic:5.x Oct 29, 2024
15 checks passed
@irfandumanx
Copy link
Contributor Author

Thank you.

By the way, in your JS you are currently overriding everything. You should be merging the existing ones. Do this instead:

Statamic.booting(() => {
    Statamic.$config.set('extensionRules', [
        ...Statamic.$config.get('extensionRules'),
        {
            label: 'Email Authenticator',
            value: 'email_authenticator:',
            example: 'email_authenticator:form'
        },
    ]);
});

I know, I just wanted to touch on the issue. Thank you.

@irfandumanx irfandumanx deleted the fix/extension-rules-undefined branch October 29, 2024 14:45
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.

2 participants