1
I have a form that is a recipe search filter. In this filter I have a checkbox group for the category:
<form method="get" action="/busca">
<h4>Categoria</h4>
<input type="checkbox" name="categoria[]" value="entrada"> Entrada
<input type="checkbox" name="categoria[]" value="principal"> Principal
<button type="submit">Buscar Receitas</button>
</form>
I wanted instead of appearing the checkbox, appeared an image (svg) to click, and when clicking on the image it marks the corresponding checkbox. I’m using the fontawesome library. Then the DIV that wanted it to be clickable, would be like this:
<div class="categoria" id="entrada">
<i class="fas fa-apple"></i><br/>
Entrada
</div>
<div class="categoria" id="principal">
<i class="fas fa-utensils"></i><br/>
Principal
</div>
Then by clicking on the Ivs, it selects the corresponding checkbox.
And one more item, when you click on the div, it changes the css class to be red for example. You could add the class ". clicked" and clicking again removes that class.
Cool, thanks. Is there any way to make more "dynamic"? Is that actually going to be various categories, input, Princpal, desserts, soups, etc., then I believe there is some way to make it more dynamic ne? Quarrel!
– Leandro Marzullo
this dynamic, it would be to have more options of choice, to leave in a more visible way?
– Gabriel Gonçalves
would be to simplify the code, for example, if it has 10 categories, I have to create 10 functions right? Isn’t there like I do a "generic" function that works for everyone? (I don’t know if I’ve understood my doubt)
– Leandro Marzullo
I changed my answer using the form @hugocsl explained.
– Gabriel Gonçalves
show, worked, just had to make a change, here " $("#" + id + " i"). toggleClass("clicked")" was applying css only to the icon, I changed it to $("#" + id + " i"). toggleClass("clicked") "$("#" + id + " i"). Closest( ".category" ).toggleClass("clicked")", I changed the answer
– Leandro Marzullo