Fix number inputs not syncing to dict until blur
dict_number() only wrote to seq[key] on blur, so changing a value (e.g. via spinner arrows) and immediately clicking Save could race the save ahead of the blur on the server. Now also syncs on update:model-value so the dict is always current. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -89,7 +89,7 @@ def dict_input(element_fn, label, seq, key, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def dict_number(label, seq, key, default=0, **kwargs):
|
def dict_number(label, seq, key, default=0, **kwargs):
|
||||||
"""Number input bound to seq[key] via blur."""
|
"""Number input bound to seq[key] via blur and model-value update."""
|
||||||
val = seq.get(key, default)
|
val = seq.get(key, default)
|
||||||
try:
|
try:
|
||||||
# Try float first to handle "1.5" strings, then check if it's a clean int
|
# Try float first to handle "1.5" strings, then check if it's a clean int
|
||||||
@@ -99,15 +99,16 @@ def dict_number(label, seq, key, default=0, **kwargs):
|
|||||||
val = default
|
val = default
|
||||||
el = ui.number(label, value=val, **kwargs)
|
el = ui.number(label, value=val, **kwargs)
|
||||||
|
|
||||||
def _on_blur(e, k=key, d=default):
|
def _sync(k=key, d=default):
|
||||||
v = e.sender.value
|
v = el.value
|
||||||
if v is None:
|
if v is None:
|
||||||
v = d
|
v = d
|
||||||
elif isinstance(v, float) and v == int(v):
|
elif isinstance(v, float) and v == int(v):
|
||||||
v = int(v)
|
v = int(v)
|
||||||
seq[k] = v
|
seq[k] = v
|
||||||
|
|
||||||
el.on('blur', _on_blur)
|
el.on('blur', lambda _: _sync())
|
||||||
|
el.on('update:model-value', lambda _: _sync())
|
||||||
return el
|
return el
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user