Reputation: 99
Hi I don't find the correct syntax to do this ..
I have two form in 2 different tab in the homepage.
form2
is a create field of one field to form 1
I submit form1
with AJAX
$('#form-indirizzo').submit(function (e) {
e.preventDefault();
var form =$(this);
$.ajax({
type:form.attr('method'),
url:form.attr('action'),
data:form.serialize(),
success: function (data) {
-> $("#form-stufa").load(location.href+" #form-stufa>*","");
},
error: function(){
}
});
});
it saves the data but I want also go to form1
tab ( form1 have id=form-stufa) and reload it... I try this
$("#form-stufa").load(location.href+" #form-stufa>*","");
to reload but don't work..
can help
My twig file :
-page-wall -->
<div id="profile-page-wall" class="stufe col s12 m12">
<!-- profile-page-wall-share -->
<div id="profile-page-wall-share" class="row">
<div class="col s12">
<ul class="tabs tab-profile z-depth-1 light-blue">
<li class="tab col s3"><a class="white-text waves-effect waves-light active" href="#UpdateStatus"><i class="mdi-editor-border-color"></i> REGISTRA STUFA</a>
</li>
<li class="tab col s3"><a class="white-text waves-effect waves-light" href="#AddPhotos"><i class="mdi-image-camera-alt"></i> Lista Stufe registrate</a>
</li>
<li class="tab col s3"><a class="white-text waves-effect waves-light" href="#CreateAlbum"><i class="mdi-image-photo-album"></i> Aggiungi Indirizzo</a>
</li>
</ul>
<!-- UpdateStatus-->
<div id="UpdateStatus" class="tab-content col s12 grey lighten-4">
{{form_start(form,{'attr':{'id':'form-stufa'}})}}
{{form_widget(form)}}
<input id="salva_stufa" class=" btn" type="submit" value="Salva" />
</div>
</div>
{{form_end(form)}}
</div>
</div>
<!-- AddPhotos -->
<div id="AddPhotos" class="tab-content col s12 grey lighten-4">
</div>
<!-- CreateAlbum -->
<div id="CreateAlbum" class="tab-content col s12 grey lighten-4">
{{form_start(form_indirizzo,{'attr':{'id':'form-indirizzo'}})}}
{{form_widget(form_indirizzo)}}
<div class="row">
<div class="col s12 m12 right-align">
<!-- Dropdown Trigger -->
<input id="salva_indirizzo" class=" btn" type="submit" value="Salva" />
</div>
</div>
{{form_end(form_indirizzo)}}
</div>
</div>
</div>
MY route :
Upvotes: 0
Views: 547
Reputation: 763
Try this. $("#form-stufa")
if you want to click on success tab then call click
event of JQ.
$('#form-indirizzo').submit(function (e) {
e.preventDefault();
var form =$(this);
$.ajax({
type:form.attr('method'),
url:form.attr('action'),
data:form.serialize(),
success: function (data) {
// For redirection
setTimeout(function(){window.location.href="youURL#form-stufa"},500);
// This is for click the tab after success callback.
//setTimeout(function(){$("#form-stufa").click()},500);
},
error: function(){
}
});
});
Upvotes: 1