Home Forums Porto Template ios-switch

This topic contains 3 replies, has 2 voices, and was last updated by  Support 4 months ago. This post has been viewed 189 times

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10020997

    didi
    Participant

    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


    #10021005

    Support
    Keymaster

    Hello, 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


    #10021012

    didi
    Participant

    sorry 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 : unchecked

    to 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


    #10021013

    Support
    Keymaster

    Hello, 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');

Viewing 4 posts - 1 through 4 (of 4 total)