Skip to content

Commit

Permalink
Merge pull request #231 from maxfordham/fix-array-remove-row
Browse files Browse the repository at this point in the history
Fix array remove row
  • Loading branch information
ollyhensby authored Nov 23, 2023
2 parents 877a537 + 52aae7c commit 5e6ab47
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/ipyautoui/custom/iterable.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ def _type(self, proposal):
@tr.observe("length")
def _length(self, on_change):
if self.length == 0:
if self.add_remove_controls == ItemControl.append_only or self.add_remove_controls == ItemControl.append_only:
if (
self.add_remove_controls == ItemControl.append_only
or self.add_remove_controls == ItemControl.append_only
):
self.display_bn_add_from_zero(True)
else:
pass
Expand Down Expand Up @@ -223,9 +226,16 @@ def _add_remove_controls(self, on_change):
def _align_horizontal(self, on_change):
flip(self.bx_boxes, self.align_horizontal)

@property
@property
def map_key_value(self):
return {b.key: (lambda w: w.value if hasattr(w, "value") or hasattr(w, "_value") else None)(b.widget.value) for b in self.boxes}
return {
b.key: (
lambda w: w.value
if hasattr(w, "value") or hasattr(w, "_value")
else None
)(b.widget.value)
for b in self.boxes
}

def display_bn_add_from_zero(self, display: bool):
if display:
Expand Down Expand Up @@ -254,7 +264,7 @@ def __init__(self, **kwargs):
self._post_init(**kwargs)

def _post_init(self, **kwargs):
pass # NOTE: this can be overwritten to provide customisation
pass # NOTE: this can be overwritten to provide customisation

def _init_controls(self):
[self._init_row_controls(key=i.key) for i in self.boxes]
Expand Down Expand Up @@ -369,7 +379,7 @@ def remove_row(self, key=None, fn_onremove=None):
)
return None
if len(self.boxes) <= 1:
pass
self.display_bn_add_from_zero(display=True)
if key is None:
print("key is None")
key = self.iterable[-1].key
Expand All @@ -383,7 +393,6 @@ def remove_row(self, key=None, fn_onremove=None):
self._watch_validate_change("")



class AutoArray(Array):
allOf = tr.List(allow_none=True, default_value=None)
items = tr.Dict(allow_none=True, default_value=None)
Expand Down

0 comments on commit 5e6ab47

Please sign in to comment.