Checklist not works when Default value selected
Hi there,
I'm passing some array values on loading the page based on this checklist has selected by default, working fine, then if I uncheck default checked list then send it to other php file but it remains selected only actually it will not be selected. this is the issue.
hobbiesinfo.php file
$arrInterestList = array(1=>"Adventure sports",2=>"Book clubs",3=>"Computer games",4=>"Health & fitness",5=>"Internet",6=>"Learning new languages",7=>"Movies",8=>"Music",9=>"Politics",10=>"Reading");
// This will make selected default values
$IList['type'] ="checklist";
$IList['model'] ="Interests_Selected";
$IList['label'] ="Intersts";
foreach($arrInterestList as $key=>$Options){
$IList['options'][$key]['label'] = $Options;
$IList['options'][$key]['slaveTo'] = in_array($key,$arrInterestChecked)? '1':'0';
}
$Selectl_dtls['Interests_Selected'] = explode("~",$varfo["Interests_Selected"]);
Let we assume Computer games and Health & fitness are selected by default again I edit that options to uncheck and send it by submit button but still it shows as selected. The following is my controller.
mainApp.controller("Lyfstyle_Cntrl", ['$scope','$http', '$compile', function($scope, $http, $compile){
$scope.myData = {};
$scope.myData.Lyfstyle_Edit = function(item, event) {
var responsePromise = $http.get("https://www.xyxyxyxyxyx.com/hobbiesinfo.php");
responsePromise.success(function(data, status, headers, config) {
$scope.LifestyleTemplate = data[0];
$scope.LyfstyleFormData = {};
$scope.LyfstyleFormData = data[1];
var template = '<dynamic-form template="LifestyleTemplate" ng-model="LyfstyleFormData" ng-submit="processLifeStyleForm()"><legend>Hobbies Info</legend></dynamic-form>';
var elem = angular.element(template);
angular.element(document.getElementById("profileAboutContainer")).append(elem);
$compile(elem)($scope);
$scope.LifestyleTemplate={}
});
responsePromise.error(function(data, status, headers, config) {
alert("AJAX failed!");
});
}
$scope.processLifeStyleForm = function() {
alert('lll');
// Posting data to php file
$http({
method : 'POST',
url : 'https://www.xyxyxyxyxyxyxy.coml/hobbiesinfo_submit.php',
data : $scope.LyfstyleFormData, //forms user object
headers : {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function(data) {
if (data.errors) {
// Showing errors.
$scope.errorName = data.errors.name;
$scope.errorUserName = data.errors.username;
$scope.errorEmail = data.errors.email;
} else {
$scope.message = data.message;
}
});
};
}]);
hobbiesinfo_submit.php file
$HobbiesReqstData = json_decode(file_get_contents('php://input'), true); print_r($HobbiesReqstData); O/P [Interests_Selected] => Array ( [1] => 1 [4] => 1 [7] => 1 ) still showing as selected.
What trying to do is, load set of checklist with default values then user can edit check and uncheck any options, after submit have to get selected checklist, any help is appreciated
Thanks