-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Relation with valueField: title looses relation on update #2063
Comments
There's more than one way to handle this, but I'm starting to think the approach championed by @Undistraction might be best, as it's not a hard feature to add. That is, providing placeholders in default values, including a fields:
- { name: id, widget: hidden, default: "{{uuid}}" } @Undistraction I'm not seeing an issue specific to this but I know we've discussed it. Please link if you feel there's an issue that this is duplicating. Update: There's the potential for this to get hacky, though. UUID is a straightforward use case, but if we add other placeholders, like field names, it will be odd when edits to those fields don't impact a hidden field that uses them in interpolation. And when you consider that case, it becomes clear that we're not really looking for defaults, but values that are set or updated based on the situation. Which brings me back to events. Having a hard time finding a case besides unique identifiers that this approach really works well for I guess. What do you think? |
@erquhart I guess we are talking about several cases:
I think the first two are good candidates for supporting interpolation, the third is, as you outline more problematic, because the result of the interpolation will only be correct when it is first created / populated. If any of the fields used in the interpolation change, the interpolated field will not be updated. To be honest, I hadn't really considered the third case. I had been seeing the use of interpolation as being a more dynamic thing used for displaying data rather than storing it. |
@FredrikSigvartsen The way I'm currently handling your problem is with a UUID widget that creates a field with a unique id for each collection item. The UUID will never change, so I use that as a stable connection for relations. The problem with this approach is that due to an existing bug, you cannot use another field to represent that relation to your users, so they will see each relation listed by its UUID instead of its title or other human-readable field. Unfortunately this makes this approach next to useless. |
Note, the display value issue will be addressed in #1936, which should merge soon. @Undistraction how are you handling the display of your UUID widget? Is it visible? |
Got it. Just curious to know how you were handling it. Sent with GitHawk |
@erquhart FWIW ideally it would be hidden as it isn't something a user should see or care about. I seem to remember the only way to hide a widget is to set it as of |
Thank you guys for good answers. @Undistraction , since this uuid widget is not yet available, do you have an (code) example of your Custom UUID Widget? |
@FredrikSigvartsen on holiday with no access to my code, but take a look at the link in my above reply. I based it on the code outlined in that issue. |
Thanks, solved the issue with the hacky UUID. This is the custom widget I used:
Looking forward to the fix regarding the displayValue. |
I just ran into this need for a UUID widget that is hidden too. Would be nice to have for sure. In the meantime I hacked the ref to also do |
Another issue that could be fixed at the same time : |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale. |
In #1063 they are running into the this issue and are proposing to solve it by allowing use of the slug. |
Another way to handle this would be to allow relation to point to the relative file path of the related objects. The file paths don't change once created. |
@mhagmajer could you give example how this would look like in the yaml file? |
Closing this via #3659, as the relation widget now supports string templates and using the slug for the relation. |
Describe the bug
I'm using NetlifyCMS and GatsbyJS. I'm having a problem to make it easy for the customer to make relations through other pages with the relation-widget in Netlify CMS. The problem appears when the customer is updating the title field:
- {label: "Product category", hint: "Search category name", name: "productCategory", widget: "relation", collection: "categories", searchFields: ["title"], valueField: "title", displayFields: ["title"]}
To Reproduce
Expected behavior
I would expect the relation to be preserved even though the title is changed. There are multiple ways to handle this, as far as my knowledge goes:
Please suggest other solutions to this issue.
Applicable Versions:
CMS configuration
Additional context
Thank you in advance, and thank you for providing Netlify CMS! I really enjoy it as a developer.
The text was updated successfully, but these errors were encountered: