Wikiki / bulma-switch

Bulma's extension to display checkbox as a switch
MIT License
108 stars 66 forks source link

form post #54

Closed ghost closed 4 years ago

ghost commented 4 years ago

I have developed a form (POST method) which contains some switches, but they send "on" and nothing instead of "true" and "false".

switch example `

                </div>`

switch handling function document.querySelectorAll(".switch").forEach(function (swt) { swt.addEventListener("click", function (e) { swt.value = swt.checked; }); });

Wikiki commented 4 years ago

Are you using Laravel as backend ? Seems more related to your framework which handle request than the package (bulma-switch does not change browser/framework behavior only design).

ghost commented 4 years ago

I am running this website on a development board (ESP8266) and I am correctly getting all the parameters of the post request (considered that the form has also text inputs) apart from those

Wikiki commented 4 years ago

The value "on" is the default one (If the value is not otherwise specified, it is the string on by default). See: https://developer.mozilla.org/fr/docs/Web/HTML/Element/Input/checkbox for more understanding on how checkboxes are working.

ghost commented 4 years ago

I know but my javascript code was supposed to change switches' value depending on their checked or not attribute. Doesn't it? How should it be changed?

Wikiki commented 4 years ago

not sure you can dynamiccally change a checkbox value this way. because the value is sent only if checkbox is checked. if not, no value at all for this element will be sent with the form. so you can't try setting true/false as value and check if meas-hum is true/false because meas-hum will not be set in form data if not checked. hard code the value in html and check if meas-hum exists in form data when form is submitted.

ghost commented 4 years ago

unfortunately I cannot do that, I need some kind of javascript handling