liform-react icon indicating copy to clipboard operation
liform-react copied to clipboard

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

Open jakub-zawislak opened this issue 7 years ago • 2 comments

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.

jakub-zawislak avatar May 24 '18 09:05 jakub-zawislak

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 :|

JBerendsenUNET avatar Feb 05 '19 14:02 JBerendsenUNET

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 https://github.com/epoberezkin/ajv/issues/824

mringler avatar Jul 24 '19 13:07 mringler