Giter VIP home page Giter VIP logo

Comments (3)

1cg avatar 1cg commented on August 15, 2024

This is the value being returned by the .value property for the checkbox. My understanding is that typically checkboxes have a value attribute, and that value is included if the checkbox is checked and excluded if it is not. It appears that if no value is set for the checkbox, "on" is the default. This isn't htmx specific as far as I know.

from htmx.

NealWebb avatar NealWebb commented on August 15, 2024

@mqudsi Review here for more details on how the model binder works with respect to checkboxes. This is written from the standpoint of a Razor Pages project but applies to MVC as well. Below is a snippet that works just fine.

<form hx-get="/">
    <input type="hidden" name="handler" value="foo" />
    <div>
        <label>Test 1</label>
        <input asp-for="Test1" /> <!-- Tag helper automatically sets the value to true -->
        <!-- The tag helper will automatically generate a hidden input with a value of false -->
    </div>
    <div>
        <label>Test 2</label>
        @Html.CheckBoxFor(m => m.Test2)
        <!-- The HTML helper does the same work as the tag helper -->
    </div>
    <div>
        <label>Test 3</label>
        <input type="checkbox" data-val="true" id="Test3" name="Test3" value="true" @Model.Test3 : "checked" ? "" />
        <input type="hidden" value="false" name="Test3" />
        <!-- Here we create the hidden input and set the values manually -->
    </div>
    <button type="submit">Send</button>
</form>

from htmx.

mqudsi avatar mqudsi commented on August 15, 2024

Yup, mea culpa. Thanks!

from htmx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.