A checklist allows you to post a subject to a channel. Channel participants can choose from the items you specify, and the results can be viewed by everyone in the channel.

Here is a sample of what a complete checklist implementation can look like:

Create Checklist

The following example creates a checklist for a potluck.

var myChannel = ...; // create a checklist and publish it to the channel var checklist = new Max.Checklist({ name: "Items for potluck", subject: "What items will you bring?", items: ["Buns", "Burgers", "Chips"] }); // publish the checklist to a channel checklist.publish(myChannel).success(function(mmxMessage) { // do something with checklist object }).error(function(err) { // handle error on failure });

Listen for Incoming Checklist Identifiers

Participants of the channel can listen for incoming checklist identifiers, which contain a checklistId we can use to get the checklist object from the server.

// register a listener to listen for new checklists or answers and update list var listener = new Max.EventListener('receivedMessageListener', function (mmxMessage) { var typedPayload = mmxMessage.payload; var checklistId = typedPayload && typedPayload.objectType && typedPayload.objectType.indexOf(Max.MessageType.CHECKLIST) != -1 ? typedPayload.objectId : null; checklistId = checklistId || typedPayload.checklistId; } }); Max.registerListener(listener);

Get the checklist object from the server using a checklistId (checklist identifier).

var checkListId = ...; Max.Checklist.get(checklistId).success(function (checklist) { // do something with checklist object }).error(function(err) { // handle error on failure });

The checklist object contains all the information needed to display a checklist in your user interface.

var name = // A user-friendly name of the checklist. var subject = myCheckList.subject // The subject of this checklist. var items = myCheckList.items // A list of the available checklist items. var extras = myCheckList.extras // A user-defined object used to store arbitrary data will can accessed from a {Max.CheckList} instance. var endDate = myCheckList.endDate // The date this checklist ends. After a checklist ends, users can no longer select items.

Checklist Items for Participants

Participants can choose one or more items.

// create an array of the CheckListItems chosen by the current user. var option1 = myCheckList.options[0]; var option2 = myCheckList.options[2]; var selectedOptions = [option1, option2]; { // options have been chosen }).error(function(err) { // handle error on failure });

Listen for Incoming CheckListSelections

Channel participants can listen for incoming CheckListSelection to display them in the user interface.

var listener = new Max.EventListener('myListener', function(myMessage) { if (myMessage.contentType && myMessage.contentType.indexOf(Max.MessageType.CHECKLIST_SELECTION) != -1) { // the incoming message contains a checklistSelection var typedPayload = myMessage.payload; var checkListID = typedPayload.checklistId; var checklistName =; // checklist name var checklistSubject = typedPayload.subject; // checklist question var checklistDeselections = pollAnswer.deselectedItems // the deselectedItems property is a list of CheckListItems deseleted by the sender var checklistSelections = pollAnswer.selectedItems; // the selectedItems property is a list of CheckListItems seleted by the sender var senderUserId = myMessage.sender.userId; } }); Max.registerListener(listener);

If the current user has voted in the checklist, the selected CheckListOption(s) can be obtained from the checklist object.

var myCheckList = ... var myChoices = myCheckList.mySelections // a list of CheckListItems selected by the current user

Obtain Checklist Results

There are several ways to obtain checklist results.

  • Get the latest checklist object from the server using a checklistId:

    var checklistId = ... Max.Checklist.get(checklistId).success(function (checklist) { // do something with checklist object }).error(function(err) { // handle error on failure });

  • Refresh results for an existing checklist object:

    var myCheckList = ...; myCheckList.refreshResults().success(function() { // the results for checklist object 'myCheckList' have been updated }).error(function(err) { // handle error on failure });

  • Use a listener to update existing checklist objects from the incoming checklistSelection. This method saves a round-trip to the server, updating the checklist results dynamically when a checklistSelection is received.

    var myCheckList = ...; var checklistSelection = ...; myPoll.refreshResults().success(function(checklistSelection) { // the results for poll object 'myCheckList' have been updated }).error(function(err) { // handle error on failure });