Solved

Set checkbox value?  AngularJS and data model.

Posted on 2014-09-23
16
3,471 Views
Last Modified: 2014-09-24
row.entity.noteRead shows up as "True" or "False" when I debug.

All the other data is getting set, but the checkbox is not!

'<input type="checkbox" class="includeCheckBox" ng-model="row.entity.noteRead" ng-click="toggleCustomerInclude(row.entity.noteRead)">'

Open in new window



More context:

helpDeskModule.controller("notesController", function ($scope, ticketServices) {
   
       ticketServices.getTicketNotes(name).then(function (notesList) {
        $scope.notes = notesList;
    }, function () { });

    $scope.gridOptionsNotesCustomer = {
        data: 'notes',
        columnDefs: [            
            { field: 'noteDetailID', displayName: 'ID', width: 50, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'detailNote', displayName: 'Detail Note', width: 300, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteType', displayName: 'Note Type', width: 80, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'detailCreateDate', displayName: 'Detail Create Date', width: 150, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'workOrderCreateDate', displayName: 'WorkOrder Create Date', width: 170, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'dBFileID', displayName: 'DBFileID', width: 70, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteRead', displayName: 'Read', width: 60, cellTemplate: '<input type="checkbox" class="includeCheckBox" ng-model="row.entity.noteRead" ng-click="toggleCustomerInclude(row.entity.noteRead)">' }
        ],
        showFilter: true,
        enableColumnResize: true,
        enableColumnReordering: true,
        multiSelect: false,
    };


    $scope.toggleCustomerInclude = function (includeOnCustomerRecord) {
        $scope.customerCommunication.includeOnCustomerRecord = !includeOnCustomerRecord;
    }
});

Open in new window

0
Comment
Question by:Tom Knowlton
  • 12
  • 4
16 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40340543
use ng-checked : https://docs.angularjs.org/api/ng/directive/ngChecked

<input type="checkbox" class="includeCheckBox" ng-model="row.entity.noteRead" ng-checked="row.entity.noteRead" ng-click="toggleCustomerInclude(row.entity.noteRead)" />
</div>

Open in new window

0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342196
Now it is setting BOTH checkboxes to checked, even though one is true and one is false.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342208
record 1
record 2
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342212
Sorry, here was the second time I hit the breakpoint:

rec 2
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342220
In the DEV TOOLS in Chrome:

javascript debug true / false in array of values.

In the GUI, both checkboxes  are checked:

both checked
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342225
Is it a problem with how the "truthy-ness" is being interpreted?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40342494
What about :
<input type="checkbox" class="includeCheckBox" ng-model="row.entity.noteRead" ng-checked="row.entity.noteRead=='True'" ng-click="toggleCustomerInclude(row.entity.noteRead)" />
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342526
has problems with:

ng-checked="row.entity.noteRead=='True'"

is this okay (remove single quotes around TRUTH):

ng-checked="row.entity.noteRead==True"


syntax errors go away then...
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342537
This iteration leaves both checkboxes unchecked:


 $scope.gridOptionsNotesCustomer = {
        data: 'notes',
        columnDefs: [            
            { field: 'noteDetailID', displayName: 'ID', width: 50, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'detailNote', displayName: 'Detail Note', width: 300, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteType', displayName: 'Note Type', width: 80, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'detailCreateDate', displayName: 'Detail Create Date', width: 150, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'workOrderCreateDate', displayName: 'WorkOrder Create Date', width: 170, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'dBFileID', displayName: 'DBFileID', width: 70, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteRead', displayName: 'Read', width: 60, cellTemplate: '<input type="checkbox" class="includeCheckBox" ng-model="row.entity.noteRead" ng-checked="row.entity.noteRead==True" ng-click="toggleCustomerInclude(row.entity.noteRead)" />' }

        //{ field: 'noteRead', displayName: 'Read', width: 60, cellTemplate: '<input type="checkbox" class="includeCheckBox" ng-checked="row.entity.noteRead" ng-click="toggleCustomerInclude(row.entity.noteRead)" />' }
        ],
        showFilter: true,
        enableColumnResize: true,
        enableColumnReordering: true,
        multiSelect: false,
    };

Open in new window

0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342538
Is there a way to see what Chrome "thinks" the value is for row.entity.noteRead


It comes through as a string, right?
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342644
If I just display the value of "noteRead" in a cell, this is what I see:

raw

Here is the javascript:

    $scope.gridOptionsNotesCustomer = {
        data: 'notes',
        columnDefs: [            
            { field: 'noteDetailID', displayName: 'ID', width: 50, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'detailNote', displayName: 'Detail Note', width: 300, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteType', displayName: 'Note Type', width: 80, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'detailCreateDate', displayName: 'Detail Create Date', width: 150, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'workOrderCreateDate', displayName: 'WorkOrder Create Date', width: 170, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'dBFileID', displayName: 'DBFileID', width: 70, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteRead', displayName: 'Read', width: 60, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteRead', displayName: 'Read', width: 60, cellTemplate: '<input type="checkbox" class="includeCheckBox" ng-model="notes" ng-checked="row.entity.noteRead" ng-click="toggleCustomerInclude(row.entity.noteRead)" />' }
        ],
        showFilter: true,
        enableColumnResize: true,
        enableColumnReordering: true,
        multiSelect: false,
    };

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40342670
yes, I'm supposing you've more code, I don't know how you bind your data, look like it's not the right wway

if you want to see, just add something like :
<div>{{row.entity.noteRead}}</div>
<div>{{row.entity|json}}</div>
<div>{{row|json}}</div>
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342749
Okay.

A co-worker stopped by my desk and was able to help me.  He explained this to me, I hope I have it right:

The reason the checkbox was not setting was I was using "True" instead of "true" and "False" instead of "false".  In order for angular to properly set the checkbox (using the data model) I had to be passing in "true" not "True" ... or tell angular the equivalent of "true" using ng-true-value="True".  "True" and "true" are not the same thing to angular.
0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 40342750
Thanks!
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40342762
that's why ID: 40342494

I put :  ng-checked="row.entity.noteRead=='True'"

My bad I was not clear...
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 40342798
No worries!


This seems to work:


  $scope.gridOptionsNotesCustomer = {
        data: 'notes',
        columnDefs: [            
            { field: 'noteDetailID', displayName: 'ID', width: 50, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'detailNote', displayName: 'Detail Note', width: 300, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteType', displayName: 'Note Type', width: 80, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'detailCreateDate', displayName: 'Detail Create Date', width: 150, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'workOrderCreateDate', displayName: 'WorkOrder Create Date', width: 170, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'dBFileID', displayName: 'DBFileID', width: 70, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteRead', displayName: 'Read Raw Val', width: 60, cellTemplate: '/Templates/CellTemplateWrapTitle.html' },
            { field: 'noteRead', displayName: 'Read', width: 60, cellTemplate: '<input type="checkbox" class="includeCheckBox" ng-model="row.entity.noteRead" ng-true-value="true" ng-false-value="false" />' }
        ],
        showFilter: true,
        enableColumnResize: true,
        enableColumnReordering: true,
        multiSelect: false,
    };

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question