Giter Club home page Giter Club logo

Comments (7)

brophdawg11 avatar brophdawg11 commented on June 26, 2024

What is the type of min_email_length? I don't see any TS issues if I define it as number | undefined:

type FormValidations = {
	inputs: {
		email: InputDefinition
	}
}

const min_email_length: number | undefined = 10;

const formDefinition: FormValidations = {
	inputs: {
		email: {
			validationAttrs: {
				type: 'email',
				required: true,
				minLength: min_email_length
			}
		}
	}
}

The BuiltInValidationAttrsFunction<T> allows you to define validation attributes values dependent on other form field values - see #29.

from remix-validity-state.

andrecasal avatar andrecasal commented on June 26, 2024

Ah got it!

min_email_length is number. I changed it to minLength: 4 but the error remains the same. Using the latest v0.10.0.

Should I make a repo to demo it?

from remix-validity-state.

brophdawg11 avatar brophdawg11 commented on June 26, 2024

🤔 Yeah that would help if I can't reproduce it locally. Thanks!

from remix-validity-state.

andrecasal avatar andrecasal commented on June 26, 2024

Apologies for the delay. I'll reproduce it during the weekend 👍

from remix-validity-state.

andrecasal avatar andrecasal commented on June 26, 2024

Here's a reproduction of the issue.

from remix-validity-state.

brophdawg11 avatar brophdawg11 commented on June 26, 2024

Ah ok. Sorry it wasn't clear to me that your error was happening in the JSX not the form definition. This error is because you're spreading the formDefinition validationAttrs onto the <input> directly instead of using useValidatedInput/getInputAttrs as follows:

const Index = () => {
  const actionData = useActionData<ActionData>();
  let { getInputAttrs } = useValidatedInput({
    formDefinition: formValidations,
    name: "email",
  });
  return (
    <Form method="post">
      <input {...getInputAttrs()} />
      <button type="submit">Submit</button>
      <p>Email: {actionData?.fields?.email}</p>
    </Form>
  );
};

In order to support dynamic validation attribute values the definition has to accept both number or a function returning a number. useValidatedInput/getInputAttrs is then what executes the function if needed and results in a narrowed number value for minLength.

from remix-validity-state.

andrecasal avatar andrecasal commented on June 26, 2024

Ah, I got confused with the documentation, got it, thanks!

from remix-validity-state.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.