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

Remove predefined attribute values from components #337

Open
myFavShrimp opened this issue Jul 31, 2024 · 0 comments
Open

Remove predefined attribute values from components #337

myFavShrimp opened this issue Jul 31, 2024 · 0 comments

Comments

@myFavShrimp
Copy link

Hey, first of all thank you for creating this library!

I am working on a larger project where I use MDUI with HTMX. When sending form data to a server with htmx, the submit button adds an empty field without a value to the request. I created a minimal example to reproduce:

<!DOCTYPE HTML>
<html lang="en" class="mdui-theme-dark">
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
    <meta content="width=device-width,initial-scale=1.0" name=viewport>

    <script src="static/external/htmx.js"></script>

    <link rel="stylesheet" href="https://unpkg.com/mdui@2/mdui.css">
    <script src="https://unpkg.com/mdui@2/mdui.global.js"></script>

    <script src="https://unpkg.com/[email protected]"></script>
</head>
<body>
    <!-- fake api that allows all cors traffic -->
    <base href="https://jsonplaceholder.typicode.com">

    <form hx-post="/posts">
        <mdui-top-app-bar-title>
            Title
        </mdui-top-app-bar-title>

        <mdui-text-field label="Username" name="username"></mdui-text-field>
        <mdui-text-field label="Password" name="password"></mdui-text-field>

        <mdui-button type="submit">Login</mdui-button>
    </form>
</body>
</html>

With the above example, here is what the login button looks like in the dom:

image

HTMX sees the name and the value attributes and includes them in the form data (which is expected behavior with htmx).

Here is what the form data looks like with the code above:
image

I found an example on the lit.dev playground where the properties of components are defined as optionals. The attributes are not displayed there because they are left undefined by default. On the ButtonBase in MDUI the attributes have a default value which is an empty string. I think attributes in MDUI should be made optional as well as empty string values still have a value (which is a string without any characters) while undefined is, as far as I know, the expected way to mark something optional in JavaScript.

Thanks again for creating MDUI. I hope this can get resolved 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant