-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Hidden widget fails to show up in front matter (Hugo) #2294
Comments
I'm having the same issue where I try to set a hidden field with a default value and it won't show up. Applicable Versions:
I've noticed however that this issue only occurs inside file collections. Folder collections work as expected. Files have to be present at first edit while folder entries can be created on the fly. Might be related to the issue? |
I have the same issue as well, but in combo with Gatsby. Can someone take a look at this? This issue is already a couple of months old. |
+1, same issue with file collections. PS. I find that any widget with 'default' option set won't work in file collection |
Yup the default option only works for folder collections and more specifically while trying to create a new entry. @jonas-sk are you still having issues with the default option on your folder collections? |
Also, forgot to add that the default option now works on the |
Isn't that something that should be mentioned in the docs? Also: Is there a specific reason for that? Adding default values seems really useful everywhere not just folder collections. |
A default value can only ever apply when creating a new entry. If you load an existing entry, it has to be loaded as-is, otherwise fields intentionally left blank would keep being populated with default values every time you edit the file. File collection entries can't be created - they're one-offs and must already exist in your repo, so the concept of defaults simply doesn't apply. That said, if you want to open a PR to add a note about this in our docs, please do! |
Thats kind of the point of a default value isnt it!? If no value is given and a value is required insert the defined default value. The field would stay blank if no default value was defined. In case of further edits now there is a value set already (the previous default value) so the system should not overwrite that with the default again.
The file has to exist but it can be empty. The information which is the important part can be added at a later date through widgets. So either the cms has to make sure that file collections contain the information according to the config from the moment the file is added/loaded or it has to deal with the fact that it can be added later through widgets and make use of all the options provided. This current system seems like it has a design flaw because it expects the code to be written in a certain way while providing other options and silently ignoring those options. |
I feel like we're missing each other here. Let me float a scenario:
At this point, all of those fields that were intentionally made blank have been repopulated with default values again. The user would have to go and delete them all again before saving. And they would have to remember which ones they wanted deleted - if this is a different user than the creator, they may not know. Finally, this whole scenario replays every time the entry is changed. This is why default values can't ever be used in existing entries, hope that makes sense.
Same logic applies here - the CMS does not know if this existing entry is empty because it's waiting to be populated for the first time, or because it's intentionally empty. The above scenario applies here as well. This really doesn't make sense for file collections - they're one off, so you have to create a distinct configuration object for each file and manually create the file. When you create the file, just add the default value in the file itself. |
You're looking at a lot of variables here, it isn't that complicated. Required fields are not a part of this discussion, so we can simplify things by leaving those out of mind. For optional fields that are blank but have a default value set in config, we can either:
Either way we are making an assumption. We have no way of knowing whether the field is intentionally blank. This is the only issue being discussed here. |
Why are required widgets not part of the discussion? Any widget is And if requiered it should not be able to be empty (except for when first initialized) because you per definition require a value to work with. I'm sorry but I really can't follow your train of thought here. |
So the single change you're looking for is for empty required fields to have default values applied. Is that right? |
Yes, I guess thats the most essential point. Next up if this is applied consistently it would solve the issue of file collections and default values. Because then you could conclude by logic that a file collection with empty required fields is loaded for the first time and defaults should apply (-> throw error if no default present). On a completly different note: Filtered collections. Use case: I'm currently working on a backend thats supposed to handle news based on tags. So for example a news article may have the tags However if I want to only display articles with those tags when selecting this collection I can't pass multiple values to filter by. I haven't been able to find the exact spot in the code where this filtering happens. Could you please give me a pointer to where the Sidenote in a sidenote: Your jsonConfigSchema doesn't validate the |
Agreed, a loaded entry should have empty required fields populated with default values, always. |
Closing as stale |
Describe the bug
Using Hugo (specifically Victor Hugo), when setting a hidden widget, the key-value combination doesn't appear in the front matter of the generated document.
To Reproduce
I haven't thoroughly tested the exact conditions. However, this is what I did:
In my case the problem manifested in both folder and file collections and in both new files created via the UI and old files edited in the UI.
Expected behavior
The hidden widget should manifest in the front matter as a key-value combination. For example, when I have
- {label: "Layout", name: "layout", widget: "hidden", default: "about"}
,layout: about
should appear in the front matter of that file.Applicable Versions:
CMS configuration
You can find it here: https://github.com/jonas-sk/pine-maastricht/blob/master/site/static/admin/config.yml. The problem specifically shows up in
posts
,projects
, andconference-2019
The text was updated successfully, but these errors were encountered: