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.

"should be equal to one of the allowed values" for async field

See original GitHub issue

Description

I created an Async Select widget out of react-select, this select widget can download/update options based on user input.

Steps to Reproduce

[Default enum] -> jsonschema -> Display Select with custom widget -> User type words to search -> The Select update the options -> User choose a new option -> “should be equal to one of the allowed values”

Expected behavior

The new options are allowed.

Please let me know:

  1. How can I remove this validate
  2. Or, how can I added the new options downloaded from async function and make them allowed at the widget level (field).

Actual behavior

Error: should be equal to one of the allowed values

Version

“react-jsonschema-form”: “^1.0.0”,

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
weasteamcommented, Apr 4, 2018

After many tests, I think I found the solution:

  1. Create function transformErrors to remove errors of should be equal to one of the allowed values
    transformErrors=(errors) =>{
        console.log(errors);
        var e = [];
          errors.map(error => {
            if (error.message !== "should be equal to one of the allowed values"){
                e.push(error)
            }
          });
          console.log(e);
          return e;
    }
  1. Pass the transformErrors to form:
<Form
    schema={this.state.schema}
    onChange={this.handleChange}
    formData={this.state.formData}
    transformErrors={this.transformErrors}
/>

That is it. It will ignore all validation.

0reactions
glasserccommented, Apr 13, 2018

I think if the schema can allow arbitrary values, then enum isn’t really right for this field. Modifying the schema is I guess one option, but maybe you should just override that one widget using uiSchema and provide a select widget that has an initial set of values instead of using enum to provide those values.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"should be equal to one of the allowed values" for async field
I created an Async Select widget out of react-select, this select widget can download/update options based on user input.
Read more >
async function - JavaScript - MDN Web Docs - Mozilla
An async function will return a different reference, whereas Promise.resolve returns the same reference if the given value is a promise. It can ......
Read more >
Input value validators - Async-graphql Book
Async -graphql has some common validators built-in, you can use them on the parameters of object fields or on the fields of InputObject...
Read more >
Async Validator with Value Changes - angular - Stack Overflow
You said in your question the field should be considered valid if the entered value matches a specific item. Please rephrase if I...
Read more >
2.0.0 | AsyncAPI Initiative for event-driven APIs
YAML, being a superset of JSON, can be used as well to represent a A2S (AsyncAPI Specification) file. For example, if a field...
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