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

Custom attributes names not supported when using wildcard #416

Open
oferrero opened this issue Mar 12, 2021 · 1 comment
Open

Custom attributes names not supported when using wildcard #416

oferrero opened this issue Mar 12, 2021 · 1 comment
Labels
info needed More information needed

Comments

@oferrero
Copy link

The default implementation of the attributeFormatter receives the indexed attribute name. For example something like addresses.5.line_one. This key is then used to directly fetch a matching value from the attributeNames.

Similar to the rule definitions, the attribute names there should support wildcard values.

This way we can assign a custom attribute name to all items in a collection at once.

To get around it I had to implement a custom attribute formatter that replaces the .{number}. with .*. and then use that to lookup. the correct value from the attributeNames.

  validator.setAttributeNames(attributeNames)

  validator.setAttributeFormatter((attribute) => {

    // Replaces `.{number}.` with `.*.` to try to match to a custom attribute name
    const wildcardAttribute = attribute.replace(/(.\d+.)/g, '.*.')

    // Replaces `._[` with `{blank space}` make the attribute a bit more presentable
    const spacedAttribute = attribute.replace(/[_.[]/g, ' ').replace(/]/g, '')

    return attributeNames[wildcardAttribute] || spacedAttribute
  })
@oferrero oferrero changed the title Custom attributes names not supported when using wildcard rules Custom attributes names not supported when using wildcard Mar 12, 2021
@mikeerickson mikeerickson added the info needed More information needed label Apr 24, 2021
@mikeerickson
Copy link
Owner

@oferrero I am curious how your data (and rules) appear for this implementation? I can see what you are requesting, but would like to see your implementation so that I can better advise (and potentially adjust) the internals.

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

No branches or pull requests

2 participants