Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"should be equal to one of the allowed values" error on choice field #47

Open
jakub-zawislak opened this issue May 24, 2018 · 2 comments

Comments

@jakub-zawislak
Copy link

I'm using liform-react with LiformBundle. I have a form:

$builder->add('someField', EntityType::class, [
    'label' => $this->getLabel($contact),
    'required' => false,
    'class' => 'Entity\SomeEntity',
]);

Object generated by liform:

properties: {
  someField: {
    enum: ["1", "2", "3"],
    enum_titles: ["one", "two", "three"],
    // ...
  }
}

After selecting an option, ajv returns validation error

"should be equal to one of the allowed values"

https://github.com/epoberezkin/ajv/blob/1c702d639cbf1d97dd8d44822bcaac43b3c4dc6f/lib/dot/errors.def#L102

On backend there is no validation errors.

@JBerendsenUNET
Copy link

Hi, have you already found a solution? I'm encountering the same problem. Adding an empty string within both enum and enum_titles fixes the problem but also hides the placeholder :|

@mringler
Copy link

You can change the type to be one of either null or enum (note the quotes around "null"!):

properties: {
  someField: {
    oneOf: [
        { type: "null" },
        {
          type: "string",
          enum: ["1", "2", "3"]
         }
    ]
    // ...
  }}

see ajv-validator/ajv#824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants