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.

Its possible to tell if the whole structure has been validated without errors?

See original GitHub issue

Issue Description

A function like allTheFieldOfTheNestedStructureAreTrue

I need to know if there is at least an error or not, to integrate spected with Formik

The formik hoc validate hook expect an empty object if the form has no errors, so I think to do something like

{
  validate: values => {
    const res = spected(validationSpecs, values)

    return isValid(res) ? ({}) : res
  }
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
daniele-rapagnanicommented, Aug 4, 2017

Hey, what about something like this:

const specialSpected = (spec, input) => {
  let valid = true;
 
  const failFunc = (f) => {
    if (valid) {
      valid = false;
    }
    
    return f;
  };
  
 
  const validation = validate(() => true, failFunc, spec, input);
  
  return {
    valid,
    validation
  };
}

In this way you have no performance hit because you don’t have to traverse the object again. I don’t know if a solution like this should be provided by spected itself, I can’t think of an elegant way to integrate it in the current API other than providing another function, which sounds like unnecessary complexity.

(demo: http://jsbin.com/coqodotuyo/edit?js,console,output)

1reaction
cloud-walkercommented, Aug 4, 2017

I’ve sketched out a possible isValid function, here: http://jsbin.com/seworut/edit?js,output

For @daniele-rapagnani : I don’t like to integrate the current idea either, but I still think it should be in the library, as its a common case, and I bet the most of the libraries out there will need it.

Cool trick BTW!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation Error Explanations for Genomes - NCBI - NIH
This page has explanations for individual errors that are commonly found during processing of prokaryotic and eukaryotic genomes, along with ...
Read more >
Validation errors explained - Filing candidate reports - FEC
Explanations for error messages returned when using the validator for electronic filings with the Federal Election Commission.
Read more >
What is Data Validation? How It Works and Why It's Important
If data isn't accurate from the start, your results definitely won't be accurate either. That's why it's necessary to verify and validate data...
Read more >
Unparsable structured data report - Search Console Help
This report lists structured data found on your site that could not be parsed because of a serious syntax error. The intended type...
Read more >
Understanding schema errors | HESA
What is a schema error? The schema describes the structure of the XML document (number of elements, whether an element can be empty,...
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