radio with custom input in alpacajs with jsonschema?

521 views Asked by At

I'm trying to create a field with several radio input options and an optional fill in the blank. The following schema doesn't seem to work in displaying output:

{
    "oneOf": [
        {
            "enum": [
                "Option 1",
                "Option 2",
                "Option 3"
            ]
        }, {
            "type":"string"
        }
    ]
}

What should I be doing? Thanks!

Clarification: I'd like to output:

( ) option 1
( ) option 2
( ) option 3
(X) custom [__fill in the blank here__]
2

There are 2 answers

1
Oussama BEN MAHMOUD On BEST ANSWER

I'm sorry it was my mistake I accidently overrided that fiddle. Thank you for your clarification. If you want to have that layout in your page you must use two different components, a radio group buttons and a simple text field that automatically will be appended after the radio group (but you could do better using jquery and append it in a different place in the postRender function of Alpaca. So your schema must be like this :

"schema": {
  "type": "object",
  "properties": {
    "oneOf": {
      "required": true,
      "enum": ['a', 'b', 'c', 'd']
    },
    "customResponse": {
      "type": "string"
    }
  }
}

I added more options for the fields like disabling default sorting, disabling the input text for custom response because it must be enabled only when the user choose the 4th option.

Here's a more complete fiddle.

1
Oussama BEN MAHMOUD On

your schema properties should be enclosed into a properties object and if the "oneOf" refers to the group of radio buttons it should be an object not an array.

"properties": {
  "oneOf": {
    "required": true,
    "enum": ["option1", "option2", "option3"]
  }, ////

Here's a complete fiddle, hope it helps. Tell me if you want something else.