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

Set array to blank string when array is empty (FE) #22884

Closed
wants to merge 1 commit into from

Conversation

caddoo
Copy link
Contributor

@caddoo caddoo commented Dec 19, 2024

Description:

This change ensures that jQuery's serialization sends a value to the backend even when an array is empty. By default, jQuery would omit empty arrays during serialization, which could cause issues on the backend.

Initially, I considered handling this on the backend by populating any setting with a name but no value as an empty array. However, this approach carried potential side effects for API consumers, so it was deemed too risky.

Instead, this solution is simple and low-risk. It ensures that a value is always sent to the backend, allowing settings to be processed and saved correctly without impacting existing API behavior.

Downside

This then stores the setting as an empty string array so [""] while this might look odd, it is compatible and does work.

Review

Sorry, something went wrong.

This is a trick so that jQuery's serialisation still sends a value to the backend when the array is an empty string, normally it would just strip the value.
@caddoo caddoo closed this Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant