Home › Forums › Porto – Responsive HTML5 Template › ios-switch
- This topic has 3 replies, 2 voices, and was last updated 6 years, 11 months ago by Support. This post has been viewed 1324 times
-
AuthorPosts
-
May 18, 2017 at 10:23 am #10020997didiParticipant
i’m having 2 functions one that get the status of the check box from the server
and another to update the status of the heckbox.
i saw that it the only way to set the status of the ios7switch is by this function$('#exemple').prev('.ios-switch').trigger('click')
the fact is that now when i login to the page where there is ios-switch check boxes i get the status of each checkbox from the server and change it by this $(‘#exemple’).prev(‘.ios-switch’).trigger(‘click’)
the problem is that this function triggers the change event which will display the notification !!!!!here is the code
//getnotif state $.post("../php/myprofilefct.php",{telephone : $mynum, typefct : 1}, function(data){ var notifs=$.parseJSON(data); if (notifs.notif1==1){ $('#notif1').prev('.ios-switch').trigger('click'); }; if (notifs.notif2==1){ $('#notif2').prev('.ios-switch').trigger('click'); }; if (notifs.notif3==1){ $('#notif3').prev('.ios-switch').trigger('click'); }; },'text'); //Toggle change $('input[name="switch"]').on('change', function(){ $notif1=$('#notif1').is(":checked"); $notif2=$('#notif2').is(":checked"); $notif3=$('#notif3').is(":checked"); $.post("../php/myprofilefct.php",{telephone : $mynum, notif1 : $notif1, notif2 : $notif2, notif3 : $notif3,typefct : 2}, function(data){ if (data=='ok') { var notice = new PNotify({ title: 'Mise à jour paramètres', text: 'Vos paramètres ont été misse à jours avec succés.', type: 'success', shadow: true, }); } else { var notice = new PNotify({ title: 'Mise à jour Opérateur', text: 'Nous n\'avons pas pu mettre à jour vos paramètres Nous nous excusons pour le désagrément. Veuillez réessayer plus tard ou contacter le support.', type: 'error', shadow: true, }); } });
please help how can i resolve this problem
May 18, 2017 at 9:56 pm #10021005SupportKeymasterHello, unfortunately it’s a little complicated, because the iOSSwitch is a very simple plugin and does not have any method to change the value (checked) by default, the only way is the one you mentioned.
My suggestion is that you attach the event
$('input[name="switch"]').on('change', function(){
only after you check the status with the ajax call or set the values in the server-side (not using ajax).Best Regards,
Jonas
May 19, 2017 at 12:44 am #10021012didiParticipantsorry jonas didnt get it!
just a recap
first step : when the customers connect to his account i call the server to get status of each chekbox exemple i get – notif1 checked notif 2 checkes notif3 : uncheckedto update the visual of the ios-switch checkbox of each one i have to call the click trigger event …no??
$('#notif2').prev('.ios-switch').trigger('click');
the problem is that at the same time
$('#notif2').prev('.ios-switch').trigger('click');
triggers the on change event which updates the server!!!so your suggestion is that i update the server only if the customer submits his changes with a botton?
thanks in advance
May 19, 2017 at 4:51 am #10021013SupportKeymasterHello, no, my suggestion was to do something like this:
//getnotif state $.post("../php/myprofilefct.php",{telephone : $mynum, typefct : 1}, function(data){ var notifs=$.parseJSON(data); if (notifs.notif1==1){ $('#notif1').prev('.ios-switch').trigger('click'); }; if (notifs.notif2==1){ $('#notif2').prev('.ios-switch').trigger('click'); }; if (notifs.notif3==1){ $('#notif3').prev('.ios-switch').trigger('click'); }; //Toggle change $('input[name="switch"]').on('change', function(){ $notif1=$('#notif1').is(":checked"); $notif2=$('#notif2').is(":checked"); $notif3=$('#notif3').is(":checked"); $.post("../php/myprofilefct.php",{telephone : $mynum, notif1 : $notif1, notif2 : $notif2, notif3 : $notif3,typefct : 2}, function(data){ if (data=='ok') { var notice = new PNotify({ title: 'Mise à jour paramètres', text: 'Vos paramètres ont été misse à jours avec succés.', type: 'success', shadow: true, }); } else { var notice = new PNotify({ title: 'Mise à jour Opérateur', text: 'Nous n\'avons pas pu mettre à jour vos paramètres Nous nous excusons pour le désagrément. Veuillez réessayer plus tard ou contacter le support.', type: 'error', shadow: true, }); } }); },'text');
-
AuthorPosts
This topic is marked as "RESOLVED" and can not rceive new replies.