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

Shared fields not resetting with anyOf/oneOf, "pattern" property ignored, (potentially) stale formdata #1819

Closed
3 tasks done
harrytalbot opened this issue Jun 18, 2020 · 3 comments
Labels

Comments

@harrytalbot
Copy link
Collaborator

harrytalbot commented Jun 18, 2020

Prerequisites

Description

I’m trying to create what should be a simple form, with some requirements. The form should have a dropdown with two options in it. Changing the options should load different schemas underneath – both schemas should have a shared field, with the same name, that is set a different value depending on the option picked; one schema should have an additional string field, that is required and should match a pattern.
I have tried to implement this in two ways – using a one of/anyOf and using an enum with dependencies. The behaviour of both implementations is close but not quite right to what I need.

Steps to Reproduce

My attempts are here:

With one of (or anyOf): https://tinyurl.com/y7bt3pqr
With enums and dependencies: https://tinyurl.com/y9qpjbx6

Expected behavior

Changing the option updates the shared value. When the second option is chosen, a unique field is shown that is pattern validated and is also marked required.

Actual behavior

With one of (or anyOf), changing the option does update the shared value. When the second option is chosen, the unique field is shown, but validated only against it being required – the pattern is ignored. Changing back to option one, the unique field formData is removed.

With enums and dependencies, changing the option does not update the shared value. This could be linked to #1558 – the value is not resetting to default. If option two is selected, the unique field is shown, and the required / pattern matching works correctly. Changing back to option one, the unique field formData is not removed.

I had a look through the source and from the implementation of mergeDefaultsWithFormData it looks like if formData is present for a field when changing schema, it’s supposed to override the default, so my section implementation may be failing by design.

Perhaps I’m using the schema wrong and there is a third way... suggestions appreciated. Thanks!

Version

Both 1.8.1 and 2.0.1

@epicfaace epicfaace added the bug label Jul 20, 2020
@ejamsa
Copy link

ejamsa commented Aug 24, 2020

Changing back to option one, the unique field formData is not removed.

Setting Form's properties omitExtraData and liveOmit fixed the stale formData issue.

@harrytalbot
Copy link
Collaborator Author

Setting Form's properties omitExtraData and liveOmit fixed the stale formData issue.

Sure, thanks - The main issue we have with the oneOf/anyOf implementation is the lack of validation on the unique field.

@stale
Copy link

stale bot commented Jul 22, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

@stale stale bot added the wontfix label Jul 22, 2022
@stale stale bot closed this as completed Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants