lundi 1 août 2016

Spring submit form get checkbox value not working

I cannot get "remember-me" checkbox value (getting 400 Required boolean parameter 'remember' is not present)

Trying to user @RequestParam. (as for inputs email/password). How to get checkbox value and not 400 error?

Controller


    @RequestMapping(value = "/login", method = RequestMethod.POST)
    private String doLogin(@RequestParam(value = "inputEmail") String inputEmail,
                           @RequestParam(value = "inputPassword") String inputPassword,
                           @RequestParam(value = "remember") boolean remember,
                           HttpSession session) {



HTML form

    <form class="form-login" method="post" action="/login">
                <h2 class="form-login-heading">Please log in</h2>
                <label for="inputEmail" class="sr-only">Email address</label>
                <input type="email" id="inputEmail" name="inputEmail" class="form-control" placeholder="Email address" required
                       autofocus>
                <label for="inputPassword" class="sr-only">Password</label>
                <input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="remember" value="remember-me"> Remember me
                    </label>
                </div>
                <button class="btn btn-lg btn-primary btn-block btn-login" type="submit">Log in</button>
            </form>




Search users having skills using selected checkboxes using AngularJS

I am in process of building a "User Skill Search Application" in AngularJS.

The concept is simple we have users with different skills. We want to build an application where we can see easily see if we have a user with say X and Y skills.

I have skills as checkboxes and user as list.

Now, I am stuck on how to filter the list based on selected skills.

Please see it should be an AND operation i.e. user should possess all the skills selected in checkbox.

Please see http://ift.tt/2arPCxM

angular.module("myApp", [])
    .controller("TreeController", ['$scope', function ($scope) {
     $scope.users = [
        {    "name": "User1",    "skill": ['DotNet','ASP.Net']  },
        {    "name": "User2",   "skill": ['DotNet','Oracle'] },
        {    "name": "User3",    "skill": ['Microsoft'] },  
        {    "name": "User4",    "skill": ['ASP.Net'] },  
        {    "name": "User5",    "skill": ['Oracle DBA','ASP.Net'] }
        ];

     
    $scope.nodeSearch = function (treeNodes, searchID) {
        for (var nodeIdx = 0; nodeIdx <= treeNodes.length - 1; nodeIdx++) {
            var currentNode = treeNodes[nodeIdx];
            if (currentNode.sys_id == searchID) {
                return currentNode;
            } else {
                var foundDescendant = $scope.nodeSearch(currentNode.children, searchID);
                if (foundDescendant) {
                    return foundDescendant;
                }
            }
        }
        return false;
    };
    $scope.setData = function (data) {
        var elements = [];
        if (data.chk === true && data.parent !== null) {
            elements.push($scope.nodeSearch($scope.tree, data.parent));
        } else if (data.chk === false) {
            angular.forEach(data.children, function (child, key) {
                elements.push($scope.nodeSearch(data.children, child.sys_id));
            });
        }
        angular.forEach(elements, function (element, key) {
            element.chk = data.chk;
            $scope.setData(element);
        });
    };
       
        $scope.getAllActive = function () {
        var data = [
        {    "name": "Oracle DBA",    "parent": "2",    "sys_id": "2.1"  },
        {    "name": "Microsoft",    "parent": "",    "sys_id": "1"  },
        {    "name": "Oracle",    "parent": "",    "sys_id": "2"  },  
        {    "name": "ASP.Net",    "parent": "1.1",    "sys_id": "1.1.1"  },  
        {    "name": "DotNet",    "parent": "1",    "sys_id": "1.1"  }
        ];
         var dataMap = data.reduce(function(map, node) {
                                map[node.sys_id] = node;
                                return map;
                        }, {});
                        
                        // create the tree array
                        var tree = [];
                        data.forEach(function(node) {
                                // add to parent
                                var parent = dataMap[node.parent];
                                if (parent) {
                                        // create child array if it doesn't exist
                                        (parent.children || (parent.children = []))
                                        // add node to child array
                                        .push(node);
                                        if(!("children" in node))
                                                {
                                                node.children=[];
                                        }
                                } else {
                                        // parent is null or missing
                                        if(!("children" in node))
                                                {
                                                node.children=[];
                                        }
                                        tree.push(node);
                                }
                        });
                        $scope.tree = JSON.parse(JSON.stringify(tree, null, '  '));
        };
     function initTree(tree) {
       function processNode(node) {
         angular.forEach(node.children, function(child) {
           if(processNode(child) === true) {
             node.chk = true;   
           }
         });
                
         return node.chk;
       }
            
       angular.forEach(tree, processNode);
     };
     initTree($scope.tree);
}]);
ul {
    list-style: circle;
}
li {
    margin-left: 20px;
}
<script src="http://ift.tt/1Mrw6cj"></script>
<body ng-app="myApp" ng-controller="TreeController" data-ng-init="getAllActive()">
<div style="float:left; width: 20%">
<script type="text/ng-template" id="tree_item_renderer.html">
    <input type="checkbox" ng-model="data.chk" ng-change="setData(data)"> 
    <ul>
        <li ng-repeat = "data in data.children" ng-include= "'tree_item_renderer.html'"></li>
    </ul>
</script>
<ul>
    <li ng-repeat="data in tree" ng-include="'tree_item_renderer.html'"></li>
    
    
</ul>
</div>
<div ng-repeat="user in users" style="float:right; width: 80%">
                    <header><h3></h3></header>
                                        <ul ng-repeat="skl in user.skill">
                                                <li></li>
                                        </ul>
</div>
</body>

Please feel free to modify the code :).




Show perticular divs on user selected check box

I have following requirement, before showing next div have to check atleast 1 checkbox or radio should be checked is must. it is done but, If user select window ac & select all 4 services then on nxet button should be ask for no of unist for all selected services. At last booknow button display. If he select 2 services then it ask no of units for both selected service If he select both window & split ac & then select no of services then it ask user no of units for selected services for both type window & split.

Thanks in advance.

My code as follows

<div class="container quick-box-outer">
            <div class="voffset-7">
                <div class="col-md-12">
                    <div class="panel panel-warning first current" id="step1">
                        <div class="panel-heading">What we provide</div>
                        <div class="panel-body">
                            <ul class="services-list">
                                <li>Background checked and trained technicians</li>
                                <li>30 days service guarantee</li>
                            </ul>
                        </div>
                        <div class="panel-heading">Pricing</div>
                        <div class="panel-body">
                            <ul class="services-list">
                                <li>Fixed charges for installation, uninstallation and servicing</li>
                                <li>Charges for AC repairs will be quoted upon inspection</li>
                                <li>Rs.199 inspection charges if no service is availed post inspection</li>
                            </ul>
                        </div>
                    </div>
                    <div class="panel panel-warning" id="step2" style="display:none">
                        <div class="panel-heading">What do you need?</div>
                        <div class="panel-body">
                            <div class="col-sm-12">
                                <div class="select-product">
                                    <input type="checkbox" name="windowac" id="windowac" class="mychk">
                                    <label for="windowac"> Window AC</label>
                                </div>
                            </div>
                            <div class="col-sm-12">
                                <div class="select-product last">
                                    <input type="checkbox" id="splitac" name="fliptac" class="mychk">
                                    <label for="splitac">Split AC</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-warning" id="step3" style="display:none">
                        <div class="panel-heading">What type of service do you want?</div>
                        <div class="panel-body">
                            <form id="step2">
                                <div class="col-sm-12">
                                    <div class="select-product">
                                        <input type="checkbox" name="wetservice" id="wetservice" class="mychk">
                                        <label for="wetservice"> Wet Servicing (Jet pump service not included)</label>
                                    </div>
                                    <div class="select-product">
                                        <input type="checkbox" name="dryservice" id="dryservice">
                                        <label for="dryservice"> Dry Servicing</label>
                                    </div>
                                    <div class="select-product">
                                        <input type="checkbox" name="gas" id="gas">
                                        <label for="gas"> Gas Charging</label>
                                    </div>
                                    <div class="select-product last">
                                        <input type="checkbox" name="other" id="other">
                                        <label for="other"> Other repairs</label>
                                    </div>
                                </div>

                            </form>
                        </div>
                    </div>

                    <div class="panel panel-warning last" id="step4" style="display:none">
                        <div class="panel-heading">How many ACs need Wet servicing?</div>
                        <div class="panel-body">
                            <form id="step2">
                                <div class="col-sm-12">
                                    <div class="select-product">
                                        <label for="1unit">
                                            <span class="col-md-6"><input type="radio" name="units" id="1unit"> 1</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                    <div class="select-product">
                                        <label for="2unit">
                                            <span class="col-md-6"> <input type="radio" name="units" id="2unit"> 2</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                    <div class="select-product">
                                        <label for="3unit">
                                            <span class="col-md-6"><input type="radio" name="units" id="3unit"> 3</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                    <div class="select-product">
                                        <label for="4unit">
                                            <span class="col-md-6"><input type="radio" name="units" id="4unit"> 4</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                    <div class="select-product last">
                                        <label for="5unit">
                                            <span class="col-md-6"><input type="radio" name="units" id="5unit"> 5</span>
                                            <span class="col-md-6 text-right">Rs 500</span>
                                        </label>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="panel panel-warning last" id="step5" style="display:none">
                        <div class="panel-heading">How many ACs need Dry servicing?</div>
                        <div class="panel-body">
                            <div class="col-sm-12">
                                <div class="select-product">
                                    <label for="1unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="1unit"> 1</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="2unit">
                                        <span class="col-md-6"> <input type="radio" name="units" id="2unit"> 2</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="3unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="3unit"> 3</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="4unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="4unit"> 4</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product last">
                                    <label for="5unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="5unit"> 5</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-warning last" id="step6" style="display:none">
                        <div class="panel-heading">How many ACs need Gas Charging</div>
                        <div class="panel-body">
                            <div class="col-sm-12">
                                <div class="select-product">
                                    <label for="1unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="1unit"> 1</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="2unit">
                                        <span class="col-md-6"> <input type="radio" name="units" id="2unit"> 2</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="3unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="3unit"> 3</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="4unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="4unit"> 4</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product last">
                                    <label for="5unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="5unit"> 5</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="panel panel-warning last" id="step7" style="display:none">
                        <div class="panel-heading">How many ACs need other reparing</div>
                        <div class="panel-body">
                            <div class="col-sm-12">
                                <div class="select-product">
                                    <label for="1unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="1unit"> 1</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="2unit">
                                        <span class="col-md-6"> <input type="radio" name="units" id="2unit"> 2</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="3unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="3unit"> 3</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product">
                                    <label for="4unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="4unit"> 4</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                                <div class="select-product last">
                                    <label for="5unit">
                                        <span class="col-md-6"><input type="radio" name="units" id="5unit"> 5</span>
                                        <span class="col-md-6 text-right">Rs 500</span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="panel-footer">
                        <div class="col-md-6 col-sm-6 col-xs-6">
                            <button type="submit" class="btn btn-raised btn-warning" id="prev" style="display:none;">Back</button>
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-6">
                            <a href="javascript:;" class="btn btn-raised btn-warning pull-right" id="next">Next</a>
                            <a href="javascript:;" class="btn btn-raised btn-warning pull-right" id="booknow" style="display:none;">Book Now</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    <script type="text/javascript">
    $('#next').click(function() {

        if ($('.current').find(':checkbox,:radio').length > 0 && !$('.current :checked').length) {
            alert('Select one or more options to Continue')
            return;
        }
        $('.current').removeClass('current').hide()
            .next().show().addClass('current');
        if ($('.current').hasClass('last')) {
            $('#next').hide();
            $('#booknow').show();
        }
        $('#prev').show();
    });

    $('#prev').click(function() {
        $('#booknow').hide();
        $('.current').removeClass('current').hide()
            .prev().show().addClass('current');
        if ($('.current').hasClass('first')) {
            $('#prev').hide();
        }
        $('#next').show();
    });

</script>
<script>
    $('#booknow').click(function() {
        if ($('.current').find(':checkbox,:radio').length > 0 && !$('.current :checked').length) {
            alert('Select one or more options to Continue')
            return;
        }
        window.location = "checkout.html"
    });

</script>




Buttons to select checkboxes by name

I have the following checkboxes in an HTML form.

<ul id="selection">
  <span><label>First<br><input type="checkbox" name="First"></label></span>
  <span><label>Second<br><input type="checkbox" name="Second"></label></span>
  <span><label>Third<br><input type="checkbox" name="Third"></label></span>
  <span><label>Fourth<br><input type="checkbox" name="Fourth"></label></span>
  <span><label>Fifth<br><input type="checkbox" name="Fifth"></label></span>
</ul>

I'm trying to create two buttons. One that would select the first two and one that would select all of them.
I managed to select all of them with one button using this:

<input type="button" class="check btn" onClick="select(this)" value="Select All"/>
    <script>
      $('.check:button').click(function(){
          var checked = !$(this).data('checked');
          $('input:checkbox').prop('checked', checked);
          $(this).val(checked ? 'uncheck all' : 'Select' )
          $(this).data('checked', checked);
      });
    </script>

But I can't seem to get the two buttons working.
My JavaScript knowledge is pretty limited and been searching for days, unsuccessfully for a solution that works.
Can please someone help? a detailed explanation would be awesome.




Update checkbox value in database with same name

I have checkboxes with the same name and the first insert works fine. Next time, when I want to update the values, it creates new rows.

I have two tables: education_levels and user_educations.

user_educations

id | user_id | education_id
1    83        1
2    83        2

education_levels

education_id | education
1              Middle school
2              High school
3              Bachelor’s degree
4              Master’s degree

..etc

How can I update only the checkboxes, which were checked and those that are not checked, change the value to 0. I am using PHP and ajax/jquery to post.

HTML

<div class="form-group form-group-custom" id="checkboxes">
    <div class="checkbox checkbox-inline">
        <input type="checkbox" id="Üldharidus" name="userEducationDegree[]" value="5">
        <label for="Üldharidus"> Üldharidus </label>
    </div>
    <div class="checkbox checkbox-inline">
        <input type="checkbox" id="Kutseharidus" name="userEducationDegree[]" value="6">
        <label for="Kutseharidus"> Kutseharidus </label>
    </div>
    <div class="checkbox checkbox-inline">
        <input type="checkbox" id="Kõrgharidus" name="userEducationDegree[]" value="4">
        <label for="Kõrgharidus"> Kõrgharidus </label>
    </div>
    <div class="checkbox checkbox-inline">
        <input type="checkbox" id="Alusharidus" name="userEducationDegree[]" value="1">
        <label for="Alusharidus"> Alusharidus </label>
    </div>
    <div class="checkbox checkbox-inline">
        <input type="checkbox" id="Põhiharidus" name="userEducationDegree[]" value="3">
        <label for="Põhiharidus"> Põhiharidus </label>
    </div>
    <div class="checkbox checkbox-inline">
        <input type="checkbox" id="Keskharidus" name="userEducationDegree[]" value="2">
        <label for="Keskharidus"> Keskharidus </label>
    </div>
</div>

PHP

        if(isset($_POST['userEducationDegree']) && !empty($_POST['userEducationDegree'])){
            $userEducationDegree = $_POST['userEducationDegree'];

            for ($i = 0; $i < count($userEducationDegree); $i++) {
                $user_education = $user_home->runQuery("INSERT into user_education (id, user_id, education_id) 
                VALUES (:education_experience_id, :user_id, :education_id) ON DUPLICATE KEY UPDATE user_id= VALUES(user_id), education_id= VALUES(education_id)");
                $user_education->bindparam(':user_id', $user_id, PDO::PARAM_STR);
                $user_education->bindparam(':education_id', $userEducationDegree[$i], PDO::PARAM_STR);
                $user_education->execute();
            }
        }else{
            $errors++; 
            $errors_query["status"] = 'error';
        }

I know I could give them seperate names, but I have to use same name, so in validation at least one of the options is selected.




Using checkboxes values in SQL "IN"-operator

I have a form with several checkboxes in it. Values of ticking checkboxes are used after in the SQL-query including in Excel-macro. I use these values in SQL "IN"-operator. So, everythig works. But I don't like the code for my macro.

For ticking checkboxes I use such code (and if there were more value the list would be very huge):

Public Location1 As String
Public Location2 As String
Public Location3 As String
Public Location4 As String

Private Sub OKCommandButton2_Click()
If CheckBox1.Value = True Then Location1 = "LocationValue1"
If CheckBox2.Value = True Then Location2 = "LocationValue2"
If CheckBox3.Value = True Then Location3 = "LocationValue3"
If CheckBox4.Value = True Then Location4 = "LocationValue4"
...

And for using it in SQl I use such code:

query = "SELECT Param1, Param2, Param3, Param4, 0, 0, Param5, 0 FROM Table1 " & _
"WHERE Param1 like'" & "%" & CraftDefinition.Craft & "%" & "'AND Param6>0 AND Param2 IN ('" & _
LocationDefinition.Location1 & "','" & LocationDefinition.Location2 & "','" & LocationDefinition.Location3 & "','" & _
LocationDefinition.Location4 & "')" & _
"ORDER BY Param2, Param3"

The question is: can I rewrite my code in more compact, laconic and sophisticated way? Maybe I should use another operator in SQL-part; maybe I can rewrite my VBA-part, for using only one parameter in SQl.

Thank you.




Angular and JS Filter upon non-standard checkboxes behavior

I would like create filters upon table data.

Filter should be generic (one to many filters group) and is mixed with search field. I have data, basic logic and search working, but can not find the right way to construct function which will return filtered records. All the filters have ALL as option, it's checked during onLoad, but rest checkboxes remains unchecked (customer specification), when you check one of the filter option the ALL is unchecked.

HTML and JS code:

$scope.checkedAll = [true, true];
        
  $scope.data.items = [
                {name: "Provider", value: 'provider_id', content: [
                        {name: 'Azure VM', value: 'azure_vm', selected: false},
                        {name: 'CloudForms', value: 'cloudforms', selected: false}
                        // more providers of them...
                ]},
                {name: "State", value: 'state_id', content: [
                        {name: 'Terminated', value: 'terminated', selected: false},
                        {name: 'On', value: 'on', selected: false},
                        {name: 'Off', value: 'off', selected: false}
                        //more states
                ]}
                //more filters []
        ];

  $scope.data.list = [
  {provider_id: "provider1", display_name: "name1", state_id: "on"},
  {provider_id: "provider2", display_name: "name2", state_id: "on"},
  {provider_id: "provider2", display_name: "name3", state_id: "off"},
  {provider_id: "provider2", display_name: "name4", state_id: "terminated"}
  //much more records
  ];

        $scope.optionClickedAll = function(index) {
                var checked = $scope.checkedAll[index];
                if (!checked) {
                        return;
                }
                
                angular.forEach($scope.data.items[index].content, function (element) {
                        element.selected = !checked;
                });
        }
        
        $scope.optionClicked = function(index, element) {
                var checked = element.selected;
                
                if (checked) {
                        $scope.checkedAll[index] = false;
                }
                
        }
        
        $scope.filterSelected = function(list) {

                var result = [];
                
/*              var filterIds = [];
                var itemIds = [];
                for (var i = 0; i < $scope.data.items.length; ++i) {
                        var item = $scope.data.items[i];
                        for (var j = 0; j < item.content.length; ++j) {
                                var value = item.content[j];
                                if ($scope.checkedAll[i] || value.selected) {
                                        if (filterIds.indexOf(item.value) == -1) filterIds.push(item.value);
                                        if (itemIds.indexOf(value.value) == -1) itemIds.push(value.value);
                                }
                        }
                }
*/

                for (var k = 0; k < list.length; ++k) {
                        // ...
                return result;
        }
}
<div class="col-md-2 ">
<div class="filters">
    <div class="search-box">
        <label class="filter-label">FILTERS</label>
        <div class="input-field">
            <input type="text" ng-model="searchInstances">
            <label class="">${Search}</label>
        </div>
    </div>
    <div ng-repeat="item in data.items">
        <label></label>
        <div class="checkbox-group">
            <input type="checkbox" ng-click="optionClickedAll($index)" ng-model="checkedAll[$index]" id="">
            <label for="">All</label>
            <div ng-init="parentIndex = $index">
                <div ng-repeat="element in item.content">
                    <input class="filled-in filter-all" type="checkbox" ng-click="optionClicked(parentIndex, element)" ng-model="element.selected" id="">
                    <label for=""></label>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="col-md-10 ">
    <table class="table">
        <thead>
            <tr>
                <th>Provider</th>
                <th>State</th>
                <th>Name</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="item in filterSelected(data.list) | filter:searchInstances">
                <td></td>
                <td></td>
                <td></td>
            </tr>
    </table>
</div>

It's possible to change structure of $scope.data.items. Appreciate any suggestions.