Skip to content

Commit

Permalink
Merge pull request #117 from Suraj3620/set-support-for-arrays
Browse files Browse the repository at this point in the history
Added set support for arrays
  • Loading branch information
dokempf authored Jan 22, 2025
2 parents 7ee2236 + 47b47c3 commit 1588566
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ipywidgets_jsonschema/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,12 +961,18 @@ def _resetter():
# Initially call the resetter
_resetter()

def _getter():
result = [h.getter() for h in elements[:element_size]]
if schema.get("uniqueItems", False):
result = list(set(result))
return result

wrapped_vbox[0] = self._wrap_description(
wrapped_vbox[0], schema.get("description", None)
)

return self.construct_element(
getter=lambda: [h.getter() for h in elements[:element_size]],
getter=_getter,
setter=_setter,
resetter=_resetter,
widgets=wrapped_vbox,
Expand Down
29 changes: 29 additions & 0 deletions tests/schemas/array-set.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"default": [],
"invalid": [
[
"1",
"1",
"3"
]
],
"schema": {
"description": "Bla bla",
"items": {
"default": "foo",
"type": "string"
},
"type": "array",
"uniqueItems": true
},
"valid": [
[
"foo"
],
[
"1",
"2",
"3"
]
]
}

0 comments on commit 1588566

Please sign in to comment.