Skip to content

Commit 7adc26c

Browse files
committed
Example of condition + required
Which of course is a bit of a hack and a workaround for not supporting oneOf
1 parent ef4bbe7 commit 7adc26c

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

examples/bootstrap-example.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ <h3>Schema</h3>
107107
{ name: "Array", data: 'data/array.json' },
108108
{ name: "Tab Array", data: 'data/tabarray.json' },
109109
{ name: "TitleMap Examples", data: 'data/titlemaps.json' },
110-
{ name: "Kitchen Sink", data: 'data/sink.json' }
110+
{ name: "Kitchen Sink", data: 'data/sink.json' },
111+
{ name: "Hack: Conditional required", data: 'data/conditional-required.json' },
111112
];
112113

113114
$scope.selectedTest = $scope.tests[0];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"schema": {
3+
"type": "object",
4+
"title": "Comment",
5+
"properties": {
6+
"switch": {
7+
"title": "Spam me, please",
8+
"type": "boolean"
9+
},
10+
"email": {
11+
"title": "Email",
12+
"type": "string",
13+
"pattern": "^\\S+@\\S+$",
14+
"description": "Email will be used for evil."
15+
}
16+
},
17+
"required": ["switch"]
18+
},
19+
"form": [
20+
{
21+
"type": "help",
22+
"helpvalue": "<p>Schema Form does not support oneOf (yet), but you can do a workaround and simulate certain scenarios with 'condition' and 'required' (and/or 'readonly') in the form.</p>"
23+
},
24+
"switch",
25+
{
26+
"key": "email",
27+
"condition": "model.switch",
28+
"required": true
29+
},
30+
{
31+
"key": "email",
32+
"condition": "!model.switch"
33+
},
34+
{
35+
"type": "submit",
36+
"style": "btn-info",
37+
"title": "OK"
38+
}
39+
]
40+
}

0 commit comments

Comments
 (0)