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

Add LabelPrefix context to better guess correct input labels #7710

Merged
merged 19 commits into from May 19, 2022

Conversation

fzaninotto
Copy link
Member

Fixes #7646

Instead of using the resource, the function that builds field and input labels can use the value of a context, which is set by the forms. This allows for better defaults in forms when using <ReferenceInput> and <ArrayInput>.

The change is made BC by keeping the previous behavior when the resource is passed explicitly.

I also took the opportunity to fix default input labels in <SimpleFormIterator> children (instead of resources.posts.fields.aothors.123.name, they are now resources.posts.fields.aothors.name).

@fzaninotto fzaninotto added the RFR Ready For Review label May 18, 2022
Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

SimpleFormIteratorItem should set a prefix as well if I understand correctly, shouldn't it?

packages/ra-core/src/util/getFieldLabelTranslationArgs.ts Outdated Show resolved Hide resolved
@fzaninotto
Copy link
Member Author

fzaninotto commented May 18, 2022

SimpleFormIteratorItem should set a prefix as well if I understand correctly, shouldn't it?

No, ArrayInput doesn't change the LabelPrefix, as developers will prefer to have the entire path in the message. For instance:

const PostEdit = () => (
   <Edit>
     <SimpleForm>
       <ArrayInput source="backlinks">
          <SimpleFormIterator>
             <TextInput source="url" />

ArrayInput will generate for the backlinks sources like backlinks.0.url, backlinks.1.url, etc. What the developers need is a constant label for each input, BUT keeping the context of the post: resources.posts.fields.backlinks.url. So we shouldn't try to change the prefix in ArrayInput - this is really designed for ReferenceInputs (and other inputs creating a new ResourceContext).

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

There's a linter warning left, otherwise 💪

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

Successfully merging this pull request may close these issues.

ReferenceInput label uses the wrong resource for translation message
3 participants