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

Submit component and fix for isValid state #28

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

webfrank
Copy link

Hi, I just implemented the Submit componente to handle submit button with isValid state handled.

I fixed an error in isValid computation as for me isValid should only depends on errors and not on touched.

I will make a new PR with isTouched property exposed to block, for example, transition to another page is form is touched.

@webfrank
Copy link
Author

Hi, I've handled checkbox fields and field validation with full context to be able to use yup.ref() for example.

@tjinauyeung
Copy link
Owner

Thanks for the PR. I understand what you're trying to do here... However the issue here is that with the helper components it's not possible to retrieve the form state because it's hidden within the helper components.

Instead of creating a custom Submit helper component, I rather expose a function which allows the user to retrieve the form state.

<script>
  import { getFormState } from 'svelte-forms-lib';

  const key = 'loginForm';

  const formProps = {
    key,
    initialValues: ...,
    validationSchema: ...
    onSubmit: ...
  };

  const formState = getFormState(key);
</script>

Then it's relatively easy to use the isValid and achieve your goal

<button disabled={formState$.isValid}>
  submit
</button>

@webfrank
Copy link
Author

webfrank commented Jun 4, 2020

It could a way, can you also add the isTouched property!

@callmeberzerker
Copy link

What's the status of this PR? I find the current imlementation really broken since you cannot have forms that partially update a record (because isValid wants ALL fields to be touched).

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

3 participants