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' is needed to handle separately

See original GitHub issue

I have a very simple input component.

    <MyInput
          required
          name="phone"
          validations="minLength:2"
          validationError="Phone is required and must have more than 2 characters." />

The issue is when user doesn’t input any thing and submits the form, the isValid() method will return false since the required is not met. But getErrorMessage() method is returning null. I have to add some additional code to handle required validation.

If I remove the required the props, then if user submits the form without any inputs, the minLength:2 validation will be passed.

I think in the most of cases, developers will like to let null, '' and undefined not meet validation of minLength:2, then we don’t have to handle ‘required’ separately. We can change our code like

    <MyInput
          name="phone"
          validations="minLength:2"
          validationError="Phone is required and must have more than 2 characters." />

and the error message will display when user input nothing in the form.

Or is there any possible to let getErrorMessage() method return a message when required is not met.

The comments on the https://github.com/christianalfoni/formsy-react/issues/216 is very clear but the api is convenience enough. validations prop => showError() / getErrorMessages() required prop => showRequired()

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

12reactions
ctumolosuscommented, Nov 2, 2015

So, I did some digging in the implementation and it looks like when you use the required attribute and the field has no value the validation error messages are skipped even though they are computed. It was not clearly documented, but adding { isDefaultRequiredValue: "Your error message when field is required" } to validationErrors will actually output that error message.

0reactions
Semigradskycommented, Nov 16, 2015

See #135

Read more comments on GitHub >

github_iconTop Results From Across the Web

Publication 504 (2021), Divorced or Separated Individuals - IRS
If you are unmarried, your filing status is single or, if you meet certain requirements, head of household or qualifying widow(er). If you...
Read more >
Operational Internal Controls – Penn: Office of Audit ...
Generally, the primary incompatible duties that need to be segregated are: Authorization or approval; Custody of assets; Recording transactions; Reconciliation/ ...
Read more >
Complying with Employment Record Requirements - SHRM
The Americans with Disabilities Act (ADA) requires that employee medical records be maintained confidentially and separate from an employee's general personnel ...
Read more >
Cargo Securement Rules | FMCSA
Vehicles which individually are heavier than 4,536 kg (10,000 lbs) must be secured in the same manner as heavy vehicles, equipment and machinery...
Read more >
Requirements management – planning for success! - PMI
Figure 4 shows how traceability starts off with the business requirements' outcomes/benefits and traces through the stakeholder requirements, solution ...
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