Solved

Set checkbox value?  AngularJS and data model.

Posted on 2014-09-23
16
3,544 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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)
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

628 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