Giter VIP home page Giter VIP logo

Comments (6)

triskweline avatar triskweline commented on July 3, 2024 1

The last checked checkbox with a given name is the one that goes into params.

I didn't say this correctly. This will work for keys with an [] suffix, as @adam12 mentioned. Here is a fork of @davisums' CodePen that changes the [name] to "status[]": https://codepen.io/triskweline/pen/rNbwMLj

from unpoly.

triskweline avatar triskweline commented on July 3, 2024

Unpoly autosubmits the form when the form's params ("form data") changes.

The checkboxes have the same [name]. The last checked checkbox with a given name is the one that goes into params. Hence checking other boxes before "Won't do" does not change the form's params.

You can use different names, or radio buttons.

from unpoly.

davisums avatar davisums commented on July 3, 2024

Unpoly autosubmits the form when the form's params ("form data") changes.

The checkboxes have the same [name]. The last checked checkbox with a given name is the one that goes into params. Hence checking other boxes before "Won't do" does not change the form's params.

You can use different names, or radio buttons.

It's a multiple-choice checkbox. I think that's the way those are typically rendered into HTML by both rails and django forms but I'll see if I can solve it some other way. Thanks for the help!

from unpoly.

adam12 avatar adam12 commented on July 3, 2024

It's a multiple-choice checkbox.

The [name] of a multiple choice checkbox usually ends with a [] to signify to the browser and server that there are multiple values attached.

ex.
<input type="checkbox" name="status[]">

from unpoly.

triskweline avatar triskweline commented on July 3, 2024

The [] suffix is a convention shared by many, but not all web frameworks. There is no web standard for it AFAIK.

It would technically be possible to detect multi-selects without that suffix. However doing this would somewhat complicate the callback signature of up.watch() and [up-watch]. In particular the oldValue and newValue arguments would always need to be arrays, for the rare case that we're dealing with a multi-select field.

from unpoly.

davisums avatar davisums commented on July 3, 2024

I had wanted to test if it would work with brackets. Thanks for pointing that out.

My first solution was to use Alpine for autosubmit (since it's already a dependency on this project) but I ended going with this instead on Django:

    post = request.POST.copy()
    post.setlist("status", request.POST.getlist("status[]"))
    form = FilterForm(post)

Since I don't want to use the form object to generate the HTML, this works fine in this case.

from unpoly.

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.