question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Required validation triggers if my select returns number 0.

Setting custom validation rules don’t trigger when using setValue if I pass it number 0

register(
            {
                name: 'myProp'
            },
            {
                 required: 'whoops'
             }
        );

This triggers if setValue('myProp', 0, true);

Additionally

register(
            {
                name: 'myProp'
            },
            {
                 required: 'whoops',
                 validate: (id: number) => {
                       return (id > -1 && id !== 999) || 'whoops';
                  }
             }
        );

The validate function isn’t even called if I use setValue('myProp', 0, true);

I would expect the validate function to run every time there is an update. Also, how should 0 values be used? Selects might legitimately return the number 0.

The ideal solution would be a property which allows 0 as valid?

A quick fix is to cast everything as strings 😦

Any help is appreciated 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sidonaldsoncommented, Aug 20, 2019

Thank you for the super fast response Bill!

As i’m using MUI and the select seems to need an empty string to be ‘clean’ i’m setting a defaultValue of an empty string.

const { register, unregister, setValue, watch, errors, handleSubmit } = useForm<FormState>({
        defaultValues: {
            InputName: '',
        }
    });

Therefore for me the validation was super simple - removing required was the key.

register(
            {
                name: 'InputName'
            },
            {
                validate: (id: number | string) => {
                   return id !== '' || 'whoops';
            }
);

Is this covered in the docs and I missed it? Happy to do a PR otherwise

0reactions
bluebill1049commented, Aug 21, 2019

I am going to close this issue for now, i will let you know what to update on documentation later on if you still interested 😃 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix: Validating Steam Files Stuck At 0 - Appuals.com
Users often need to verify their game files and in this error, steam gets stuck at 0% when the process is initiated and...
Read more >
How to create correct rule for validating zero via vee-validate
', validate: (value) => { // value must be > zero if (value > 0 ) return true; return false; } }); },....
Read more >
ZeroBounce - Email Validation Service and Deliverability Toolkit
Easy and effective email validation service. 98% accuracy, 24/7 customer support. Verify 100 email addresses for free – every month! Start trial today....
Read more >
Validating Zero Enum Value in the Protocol Buffer - HackerNoon
How to validate that a Protobuf message does not contain enum fields with zero value? Turn out that is not supported directly by...
Read more >
Hibernate Validator 8.0.0.Final - Jakarta Bean Validation ...
Declaring and validating method constraints ... passedDrivingTest( true ); assertEquals( 0, validator.validate( car, DriverChecks.class ) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found