Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Multiple select and checkbox arrays are not properly initialized #565

Open
lnoor opened this issue Nov 5, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@lnoor
Copy link
Contributor

lnoor commented Nov 5, 2024

Important Notice
We do not provide support through GitHub issues. For community-based help, please use either:

If you're reporting a bug, please continue with this template.

Describe the bug
A clear and concise description of what the bug is.

With a form containing a multiple select box or a set of checkboxes all having the same name the function fill_form()
will not initialize the form properly.
None of the select options and all of the checkboxes are marked as selected or checked.

Minimal Reproducible Example
Provide a minimal code snippet that reproduces the issue. This is crucial for us to understand and fix the bug quickly.

#!/bin/env python3
from fasthtml.common import *

@dataclass
class MultiSelect:
    items: list[str]

select_data = MultiSelect(items=['a', 'c'])
select_form = Form(Select(Option('a', value='a'), Option('b', value='b'), Option('c', value='c'), multiple='1', name='items'))
select_form = fill_form(select_form, select_data)
print(to_xml(select_form))

@dataclass
class MultiCheck:
    items: list[str]

check_data = MultiCheck(items=['a', 'c'])
check_form = Form(Fieldset(Label(Input(type='checkbox', name='items', value='a'), 'a'),
                           Label(Input(type='checkbox', name='items', value='b'), 'b'),
                           Label(Input(type='checkbox', name='items', value='c'), 'c')))
multiform = fill_form(check_form, check_data)
print(to_xml(check_form))

Expected behavior
A clear and concise description of what you expected to happen.

The actual outcome is:

<form enctype="multipart/form-data">
  <select multiple="1" name="items">
    <option value="a">a</option>
    <option value="b">b</option>
    <option value="c">c</option>
  </select>
</form>

and

<form enctype="multipart/form-data">
  <fieldset>
    <label><input type="checkbox" name="items" value="a" checked="1">a</label>
    <label><input type="checkbox" name="items" value="b" checked="1">b</label>
    <label><input type="checkbox" name="items" value="c" checked="1">c</label>
  </fieldset>
</form>

The desired outcome should be:

<form enctype="multipart/form-data">
  <select multiple="1" name="items">
    <option value="a" selected="1">a</option>
    <option value="b">b</option>
    <option value="c" selected="1">c</option>
  </select>
</form>

and

<form enctype="multipart/form-data">
  <fieldset>
    <label><input type="checkbox" name="items" value="a" checked="1">a</label>
    <label><input type="checkbox" name="items" value="b">b</label>
    <label><input type="checkbox" name="items" value="c" checked="1">c</label>
  </fieldset>
</form>

Environment Information
Please provide the following version information:

  • fastlite version: 0.0.13
  • fastcore version: 1.7.19
  • fasthtml version: fasthtml.git@3b6c7000df01bf10329214f4ff13918317f1fd20

Confirmation
Please confirm the following:

  • [x ] I have read the FAQ (https://docs.fastht.ml/explains/faq.html)
  • [x ] I have provided a minimal reproducible example
  • [x ] I have included the versions of fastlite, fastcore, and fasthtml
  • [x ] I understand that this is a volunteer open source project with no commercial support.

Additional context
Add any other context about the problem here.

The problem actually resides in the function _fill_item().
I have a fix ready for which I will create a PR.

Screenshots
If applicable, add screenshots to help explain your problem.

@lnoor lnoor added the bug Something isn't working label Nov 5, 2024
lnoor added a commit to lnoor/fasthtml that referenced this issue Nov 5, 2024
lnoor added a commit to lnoor/fasthtml that referenced this issue Nov 5, 2024
lnoor added a commit to lnoor/fasthtml that referenced this issue Nov 19, 2024
jph00 added a commit that referenced this issue Nov 19, 2024
fixing issue #565, improper initialization of multiple select and checkbox arrays
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant