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

How can I tell Formbit that the values are not null? #15

Open
TheFe91 opened this issue Nov 28, 2024 · 0 comments
Open

How can I tell Formbit that the values are not null? #15

TheFe91 opened this issue Nov 28, 2024 · 0 comments

Comments

@TheFe91
Copy link

TheFe91 commented Nov 28, 2024

I'm developing a form with formbit in Typescript and I ran into this problem:

I have my initialValues defined in this way

const schema = yup.object().shape({
  adataord: yup.string().required(),
  dadataord: yup.string().required(),
  lbage: yup.string().required(),
  td_flags: yup.string().required(),
});

type FormValues = {
  adataord: string;
  dadataord: string;
  lbage: string;
  td_flags: string;
};

const initialValues: FormValues = {
  adataord: '',
  dadataord: '',
  lbage: '-1',
  td_flags: '99',
};

const { write, form } = useFormbit({ initialValues, yup: schema });

I have a useState defined in this way

const [filters, setFilters] = useState(initialValues);

At a certain point I want to do

const handleOnFilter = () => {
  setFilters({ ...form });
};

However this raises a typescript error, saying that string | undefined is not assignable to type string, obliging me to do

const handleOnFilter = () => {
    setFilters({
      adataord: form.adataord!,
      dadataord: form.dadataord!,
      lbage: form.lbage!,
      td_flags: form.td_flags!,
    });
  };

I'm not getting why formbit addresses the types as nullables, while I defined them as non-nullables.
Am I making any mistake?

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

No branches or pull requests

1 participant