Comments (3)
That was my first idea but in reality, all rules should accept "empty" (null
, undefined
, ""
) value.
Because this rule is handled with the isRequired
rule (or required
property).
Example for optional field:
Now 😕:
<Field
name="myField"
validations={[
{
rule: val => !value && value !== 0 ? true : isNumber()(value)
message: 'not a number',
},
{
rule: val => !value && value !== 0 ? true : isMinNumber(1)(value)
message: 'not under 1',
},
{
rule: val => !value && value !== 0 ? true : isMaxNumber(10)(value)
message: 'not over 10',
},
]}
>
If we allow empty value 😃 :
<Field
name="myField"
validations={[
{
rule: isNumber()
message: 'not a number',
},
{
rule: isMinNumber(1)
message: 'not under 1',
},
{
rule: isMaxNumber(10)
message: 'not over 10',
},
]}
>
from formiz.
Available in version 1.0.0-rc.4
🙂
from formiz.
I think we should introduce a new validation for this kind of wanted behavior: isOptionalNumber
or something like that. So isNumber
stays the same.
from formiz.
Related Issues (20)
- Form not rendering when page is loaded in time not to make screen jump HOT 5
- React 18 asyncValidations doesn't work anymore HOT 3
- Formiz v2 - React 18 HOT 7
- Step Animations/Transitions HOT 1
- Can't See Steppers Page "previous" Button on Dark Mode HOT 3
- Add strict max & min number validations
- Use of keepUnmounted and keepPristine in same setFieldsValues
- Reset issue on v2 alpha.4 HOT 1
- Hydration - SSR HOT 3
- Async initialValues didn't work with useCollection HOT 2
- support rtl HOT 2
- FEAT: maxLength/minLength options on useCollection
- Pristine update on collection remove HOT 1
- FEAT: Add a Formiz Devtools
- useForm is not working as expected. HOT 2
- Delete collection on unmount
- Pls expose useFormContext HOT 2
- No validation for inputs of type number in firefox HOT 4
- Issue when setFieldsValues is called on mount HOT 1
- Error when hiding step B in Conditional Fields & Steps in Demos
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 formiz.