Skip to content

Commit

Permalink
fix for issue #565
Browse files Browse the repository at this point in the history
  • Loading branch information
lnoor committed Nov 19, 2024
1 parent 16d8f9a commit 611d713
Show file tree
Hide file tree
Showing 2 changed files with 323 additions and 38 deletions.
14 changes: 11 additions & 3 deletions fasthtml/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,24 @@ def _fill_item(item, obj):
if val is not None and not 'skip' in attr:
if tag=='input':
if attr.get('type', '') == 'checkbox':
if val: attr['checked'] = '1'
if isinstance(val, list):
if attr['value'] in val: attr['checked'] = '1'
else: attr.pop('checked', '')
elif val: attr['checked'] = '1'
else: attr.pop('checked', '')
elif attr.get('type', '') == 'radio':
if val and val == attr['value']: attr['checked'] = '1'
else: attr.pop('checked', '')
else: attr['value'] = val
if tag=='textarea': cs=(val,)
if tag == 'select':
option = next((o for o in cs if o.tag=='option' and o.get('value')==val), None)
if option: option.selected = '1'
if isinstance(val, list):
for opt in cs:
if opt.tag == 'option' and opt.get('value') in val:
opt.selected = '1'
else:
option = next((o for o in cs if o.tag=='option' and o.get('value')==val), None)
if option: option.selected = '1'
return FT(tag,cs,attr,void_=item.void_)

# %% ../nbs/api/01_components.ipynb
Expand Down
Loading

0 comments on commit 611d713

Please sign in to comment.