Comments (7)
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.
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.
from remix-validity-state.
Apologies for the delay. I'll reproduce it during the weekend
from remix-validity-state.
Here's a reproduction of the issue.
from remix-validity-state.
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.
Ah, I got confused with the documentation, got it, thanks!
from remix-validity-state.
Related Issues (20)
- Support checkbox/radio/textarea/select HOT 3
- Incorrect input value during async validation
- Date range validation HOT 7
- Server-only custom validation HOT 3
- Better Typescript Types on serverFormInfo.submittedValues HOT 6
- Better Typescript validation on errorMessages
- Expose form-level `valid` prop on client side for submission prevention?
- Error in validateInput useEffect Error: validateInput expected an inputEl.form to be available for input HOT 6
- type="email" is not being validated on the server HOT 6
- Type mismatch on React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement> HOT 1
- Consider allowing controlled inputs—example of problem with HeadlessUI Listbox HOT 1
- Better handling of checkbox edge cases HOT 2
- Allow conditionally rendered optional inputs HOT 1
- Feature Request: Form checkValidity method HOT 1
- Add support for min/max strings on date input HOT 2
- Validation handling HOT 1
- Fix select type HOT 3
- Question: should whole component re-render on checkbox onChange? HOT 1
- Bug updating state of select element HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remix-validity-state.