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

type: Allow insert null value to FieldArray #246

Open
Huliiiiii opened this issue Sep 3, 2024 · 5 comments
Open

type: Allow insert null value to FieldArray #246

Huliiiiii opened this issue Sep 3, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request priority This has priority

Comments

@Huliiiiii
Copy link
Contributor

In my case, I need to insert a new entry without value into FieldArray, but the current type definition does not support this.

@fabian-hiller
Copy link
Owner

Can't you add an empty value (e.g. empty string)? Feel free to share your use case and code with me.

@fabian-hiller fabian-hiller self-assigned this Sep 3, 2024
@fabian-hiller fabian-hiller added the question Further information is requested label Sep 3, 2024
@Huliiiiii
Copy link
Contributor Author

Can't you add an empty value (e.g. empty string)? Feel free to share your use case and code with me.

No, the schema is an object, and a key of object is string literal union types.

This is my schema:

v.array(
  v.object({
    language: // Union of language literals,
    localized_name: string,
  })
)

@fabian-hiller
Copy link
Owner

I understand and will check if we can allow null or undefined in such cases. In the meantime, you can change the input requirements of your schema to allow, for example undefined:

import * as v from 'valibot';

const LanguageSchema = v.picklist(['DE', 'FR', 'US']);

const LanguageArraySchema = v.array(
  v.object({
    language: v.pipe(v.optional(LanguageSchema), LanguageSchema),
    localized_name: v.string(),
  })
);

@fabian-hiller fabian-hiller added enhancement New feature or request priority This has priority and removed question Further information is requested labels Sep 4, 2024
@fabian-hiller
Copy link
Owner

Unfortunately, I couldn't find a quick fix as I encountered some more complex TypeScript errors. I may try again when I have more time or consider it when rewriting the library at some point.

@Huliiiiii
Copy link
Contributor Author

Unfortunately, I couldn't find a quick fix as I encountered some more complex TypeScript errors. I may try again when I have more time or consider it when rewriting the library at some point.

Thanks for your work. For now, changing the schema is a good workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request priority This has priority
Projects
None yet
Development

No branches or pull requests

2 participants