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

Allow setting default value of a field to that of a field in same collection #5256

Closed
lfracalossiFA opened this issue Apr 12, 2021 · 2 comments
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@lfracalossiFA
Copy link

Is your feature request related to a problem? Please describe.
This is similar in nature to #1975, but does not involve UUIDs, so I'd hoped it might be easier to achieve!

Many times when I'm creating a collection, I want to set the default value of a field to the value of a different field. For example, if I had a collection with title (for title of an article) and name (the short name/slug) fields, I'd like the default value of title to be set to the value of name. However, currently this is not possible.

Describe the solution you'd like

I'd like to be able to reference another field using something like default: '{{fields.name}}' or default: '{{slug}}'

Additional context
Here's an example of the use case I have in mind, where I have appended (see highlighting) what I expected to be possible:

Screen Shot 2021-04-12 at 5 37 46 PM

@lfracalossiFA lfracalossiFA added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Apr 12, 2021
@erezrokah
Copy link
Contributor

Hi @lfracalossiFA, I believe you can do that using the CMS preSave event:
https://www.netlifycms.org/docs/beta-features/#registering-to-cms-events

You can get the value from the name field and set it on the title field if the latter doesn't exist.

The thing is that default values are currently applied before the editor is opened and the entry is saved for the first time, so it's the default value for the field.

This suggestion can be classified as a fallback value.

Closing this issue as I think it is covered by the first bullet in #1975:

  1. Generalise the use of placeholders so that they can be used in places other than in generating the slug field.

@lfracalossiFA
Copy link
Author

Ooh, I didn't know about the preSave event. Thanks for the info there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

No branches or pull requests

2 participants