Solved

Set checkbox value?  AngularJS and data model.

Posted on 2014-09-23
16
3,444 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: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: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:knowlton
ID: 40342208
record 1
record 2
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Author Comment

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

rec 2
0
 
LVL 5

Author Comment

by: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: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: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: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: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: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: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: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: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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
replace link with jQuery 4 20
I want a tab to always be underlined when I open div then change 1 34
Add shadow behind div 5 25
html border input line 7 13
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

856 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