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

fix: field appending on duplicate should ignore non string values #11621

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JessChowdhury
Copy link
Member

What?

When duplicating a document with unique fields, we append - Copy to the field value.
The issue is that this is happening when the field is empty resulting in values being added that look like: undefined - Copy or null - Copy.

Why?

We are not checking the incoming value in all cases.

How?

Checks the value exists, is a string, and is not just an empty space before appending - Copy.

At first glance it looks incorrect to return required fields with undefined - however when duplicating a document, the new document is always created as a draft so it is not an issue to return undefined.

Closes #11373

const localizedUniqueRequired: FieldHook = ({ req, value }) =>
`${value} - ${req?.t('general:copy') ?? 'Copy'}`
hasValue(value) ? `${value} - ${req?.t('general:copy') ?? 'Copy'}` : undefined
Copy link
Contributor

@JarrodMFlesch JarrodMFlesch Mar 11, 2025

Choose a reason for hiding this comment

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

Aren't localizedUniqueRequired and localizedUnique always the same value? I know it is unrelated, but it seems odd. We should clean that up.

On another note, I do wonder what happens when you have a number field that you set to unique on duplicate. Should we set that to undefined if it is marked as unique?

Copy link
Member Author

Choose a reason for hiding this comment

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

Aren't localizedUniqueRequired and localizedUnique always the same value? I know it is unrelated, but it seems odd. We should clean that up.

Sure is, I will consolidate this

On another note, I do wonder what happens when you have a number field that you set to unique on duplicate. Should we set that to undefined if it is marked as unique?

I reverted these changes to check what is currently happening when you duplicate a unique number field - it borks and throws Something went wrong.. In the console the real error is that it tried to append - Copy and then fails field validation.

I think setting it to undefined would be best - or we could append it with a 1, but this could potentially be more confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm we actually don't seem to be handling all field types that allow the unique option. This includes:

  • Json
  • Code
  • Email
  • Number
  • Point
  • Relationship
  • Select
  • Text
  • Textarea
  • Upload

Copy link
Member Author

Choose a reason for hiding this comment

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

@JarrodMFlesch I took a stab at cleaning up that file and handling the rest of fields which can have unique: true.

I appended the number field by adding + 1 but honestly not sure how much value this provides, I could return undefined instead - what do you think?

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

Successfully merging this pull request may close these issues.

Duplicating a document publishes all the available locales
2 participants