Skip to content

Commit 4b7886d

Browse files
ebrehaultdaniele-pecora
authored andcommitted
Merge pull request #415 from bennmapes/issue-414
#414 fixes validation of ANY to validate more types of values
1 parent 1c37023 commit 4b7886d

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

projects/schema-form/src/lib/model/formproperty.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,17 @@ export abstract class FormProperty {
250250
} else if (typeof expString === 'number') {
251251
valid = !!value ? `${expString}` === `${value}` : false;
252252
} else if (-1 !== `${expString}`.indexOf('$ANY$')) {
253-
valid = value && value.length > 0;
253+
if(Array.isArray(value)) {
254+
valid = value.length > 0;
255+
} else if(typeof value === "number") {
256+
valid = true;
257+
} else if(typeof value === "boolean") {
258+
valid = true;
259+
} else if(typeof value === "string") {
260+
valid = value !== '';
261+
} else if(typeof value === "object") {
262+
valid = value !== null && value !== {};
263+
}
254264
} else if (0 === `${expString}`.indexOf('$EXP$')) {
255265
const _expresssion = (expString as string).substring('$EXP$'.length);
256266
valid = true === this.expressionCompilerVisibiltyIf.evaluate(_expresssion, {

src/app/json-schema-example/visibility-binding-example-schema2.json

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,75 @@
241241
}
242242
}
243243
},
244+
"visibleIfBinding1c": {
245+
"description": "# 6. Test 'VisibleIf' with 'oneOf' and '$ANY$' condition",
246+
"type": "object",
247+
"properties": {
248+
"anyString1c": {
249+
"type": "string",
250+
"description": "Visible component shows up with any string here.",
251+
"widget": "string"
252+
},
253+
"anyNum1c": {
254+
"type": "number",
255+
"description": "Visible component shows up if any number here",
256+
"widget": "number"
257+
},
258+
"anyBoolean1c": {
259+
"type": "boolean",
260+
"description": "Visible component shows up if any checked state",
261+
"widget": "checkbox"
262+
},
263+
"anyArary1c": {
264+
"type": "array",
265+
"widget": "select",
266+
"items": {
267+
"type": "string",
268+
"oneOf": [
269+
{
270+
"description": "Option1",
271+
"enum": [
272+
"Option1"
273+
]
274+
},
275+
{
276+
"description": "Option2",
277+
"enum": [
278+
"Option2"
279+
]
280+
},
281+
{
282+
"description": "Option3",
283+
"enum": [
284+
"Option3"
285+
]
286+
},
287+
{
288+
"description": "Option4",
289+
"enum": [
290+
"Option4"
291+
]
292+
}
293+
]
294+
},
295+
"description": "Visible component shows up if any selection here"
296+
},
297+
"visibleComponent1c": {
298+
"type": "string",
299+
"description": "Visible if any values exist in a test input",
300+
"visibleIf": {
301+
"oneOf": [
302+
{"anyString1c": ["$ANY$"]},
303+
{"anyNum2c": ["$ANY$"]},
304+
{"anyBoolean2c": ["$ANY$"]},
305+
{"anyArary2c": ["$ANY$"]}
306+
]
307+
}
308+
}
309+
}
310+
},
244311
"visibleIfBinding2a": {
245-
"description": "# 6. Test Boolean 'VisibleIf' with 'allOf' condition (check 'Warn' and 'Fail')",
312+
"description": "# 7. Test Boolean 'VisibleIf' with 'allOf' condition (check 'Warn' and 'Fail')",
246313
"type": "object",
247314
"properties": {
248315
"status2a": {
@@ -281,7 +348,7 @@
281348
}
282349
},
283350
"visibleIfBinding2b": {
284-
"description": "# 7. Test String 'VisibleIf' with 'allOf' condition (select 'Warn' and 'Fail')",
351+
"description": "# 8. Test String 'VisibleIf' with 'allOf' condition (select 'Warn' and 'Fail')",
285352
"type": "object",
286353
"properties": {
287354
"status2a": {

0 commit comments

Comments
 (0)