mardi 2 mai 2017

Spring Framework form:checkbox - How to place a tag element between the input tag and the hidden field?

This is my first question here so... well yeah let's get started.

I am using the spring form tag library in one of my projects and encountered the following problem:

I need to call a js function onmouseup on the label to a checkbox.

The problem is with the spring form:checkbox tag the output then looks like this

<input id="id" name="name" value="true" type="checkbox">
<input name="_name" value="on" type="hidden"> 
<label for="id" onmouseup="func()" >blabla</label>

Due to my style.css which uses the + selector to get the label after a checked checkbox I need something like:

<input id="id" name="name" value="true" type="checkbox">
<label for="id" onmouseup="func()" >blabla</label>
<input name="_name" value="on" type="hidden"> 

But because I want to call a function onmouseup on the label the label attribute to the form:checkbox tag won't work either :S

My input is surrounded by a div so basically using the label attribute on the form:checkbox with the onmouseup call on the div would work but it feels kinda hacky.

So to sum it up I need either a different way to get my css to work or a way to achieve the above mentioned html structure using spring. :S Thanks in advance

By the way here's the css (the rest is just styling which should not be important but I will post it if it'll help just let me know):

.switch input[type="checkbox"]:checked + label:after{
    left: 23px;
}

.switch input[type="checkbox"]:checked + label{
    background-color: #fff;
}




Aucun commentaire:

Enregistrer un commentaire