1
I own a Togglable tabs and would like to serialize the data only of the current index or active
tab.
This form is "global" so to speak, and this tabs gets inside, an example of this would be:
<form>
<div class="servicos">
<label>foo</label>
<input type="text" name="foo">
<label>foo</label>
<input type="text" name="bar">
</div>
<div class="configuracoes">
<label>foo2</label>
<input type="text" name="foo2">
<label>foo2</label>
<input type="text" name="bar2">
</div>
<button id="enviar">Enviar</button>
</form>
Let’s say I’m on the "settings" tab when saving I’d just grab foo2,bar2
.
I’ve tried it this way:
$("form").submit(function(e) {
e.preventDefault();
$(this).find('.configuracoes').serialize();
});
The return of serialize is empty, ?
$(this).find('.active').serialize();
When the tab is visible, the . active class is added to the element. So with that code he’ll only take the values of whatever’s inside the element that’s visible.– GilCarvalhoDev
@Gilsones this is exactly how I tested it, if you look at my example.
– Gabriel Rodrigues
Try it like this then:
$(this).find('.active [name]').serialize();
So he’ll take all the elements that have the attributename
(fields, texarea, select, radio, checkbox...) and will serialize– GilCarvalhoDev