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] Value is not included on some HTML tags if the supplied value is 0, False, None or "" #537

Open
1 task done
dan-hoog opened this issue Oct 21, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@dan-hoog
Copy link

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

@app.route("/test")
    def get():
        manual_form = NotStr("""<FORM METHOD="POST" ACTION="/test/manual_form">
                        <SELECT NAME="test_select_field">
                        <OPTION VALUE="">Option 0</OPTION>
                        <OPTION VALUE="1">Option 1</OPTION>
                        <OPTION VALUE="2">Option 2</OPTION>
                        </SELECT>
                        <INPUT TYPE="submit" VALUE="Submit">
                        </FORM>
                     """)
        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
  • 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:

  | -- | --   |   |   | <title>FastHTML page</title>   |   |   | <script src="https://unpkg.com/htmx.org@next/dist/htmx.min.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/[email protected]/fasthtml.js"></script><script src="https://cdn.jsdelivr.net/gh/answerdotai/surreal@main/surreal.js"></script><script src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js"></script>   | <style>:root { --pico-font-size: 100%; }</style>   | <style>:root { --pico-font-size: 65%; }</style>   |   |   |   |
  |

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 ||

@dan-hoog dan-hoog added the bug Something isn't working label Oct 21, 2024
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