AnswerDotAI / AnswerDotAI/fasthtml

[BUG] Value is not included on some HTML tags if the supplied value is 0, False, None or ""

Open
#537 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
Jupyter Notebook
Stars
7k
Forks
319
Avg merge
28m
Merged PRs (30d)
3

Description

Overall liking FastHTML and making progress on some tools.

Sample Code below illustrates this - by outputting a SELECT form both ways and showing the results is posted below:


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

**Describe the bug**
I find that using select (I think other form elements as well), some legal HTML values for Value are not generated, resulting in odd behavior on the generated page.

Within a form and an empty string as a VALUE, the output OPTION does not generate with a value field. The response value on the form becomes the payload text.

**Minimal Reproducible Example**

```python
@app.route("/test")
def get():
manual_form = NotStr("""

Option 0
Option 1
Option 2



""")
return Div(P(f"Test route with parameter"),
P("Select Form Generated by FastHTML",
Form(Select(Option("Option 0", value=""), Option("Option 1", value="1"), Option("Option 2", value="2"), NAME="test_select_field"),
Input(type="submit", value=f"Submit"),
Method="POST", Action=f"/test/fasthtml_form",)),
P("Select Form from Raw HTML", manual_form),
)

@app.route("/test/{parameter}")
def post(post_args: dict, parameter: str):
print(f"fastcrud_test_post with parameter {parameter}")
print(f"Result of test_select_field is |{post_args['test_select_field']}|")
return P(f"Test result - POSTED - parameter {parameter}"), P(f"returned value for test_select_field |{post_args['test_select_field']}|", )
```

**Expected behavior**
A clear and concise description of what you expected to happen.
The empty values should be emitted as VALUE=v in the generated HTML so they are properly reflected in HTML actions.

**Environment Information**
Please provide the following version information:
- fastlite version: 0.0.11
- fastcore version: 1.7.19
- fasthtml version: 0.6.14

**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.
Generated HTML from the /test example provided:

  |
-- | --
  |
  |
  | FastHTML page
  |
  |
  |
  | :root { --pico-font-size: 100%; }
  | :root { --pico-font-size: 65%; }
  |
  |
  |
  |


  |

Test route with parameter


  |


  | Select Form Generated by FastHTML

Option 0Option 1Option 2
  |


  |


  | Select Form from Raw HTML


  |
  | Option 0
  | Option 1
  | Option 2
  |
  |
  |
  |


  |

  |
  |
 

**Screenshots**
If applicable, add screenshots to help explain your problem.
Console response from fasthtml select form:
fastcrud_test_post with parameter fasthtml_form
Result of test_select_field is |Option 0|

Console response from raw html select form
fastcrud_test_post with parameter manual_form
Result of test_select_field is ||

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.