HTML and CSS Reference
In-Depth Information
return false;
// Check if perc-completed is >0 and task not started
// or 100 done but not completed
if ((task.percCompleted > 0 && task.status == "Not Started") ||
(task.percCompleted == 100 && task.status != "Completed") ||
(task.percCompleted != 100 && task.status == "Completed"))
return false;
return true;
}
The function returns a Boolean answer to the question:
Is the passed Task object valid for the
purposes of the application?
The code ultimately consists of a list of
if
statements that check business
rules you want to apply.
Summarizing results
Before you can validate a task, you need to collect the actual data and copy that into a
Task
object.
In WinJS, you can't rely on the system doing most of the work for you. If you use C# and XAML to
write Windows Store applications, then you can force the system to take the original
Task
object
you provided to initialize the form and update it with any changes the user makes through the user
interface widgets. This feature is known as
two-way data binding
, but is not supported in WinJS. As a
result, you need to introduce a function like the one below. You can copy the code below in
todolist.js
.
TodoList.getTaskFromUI = function () {
var task = new Task();
// Read the subject of the task
var taskSubject = document.getElementById("taskSubject");
task.description = taskSubject.value;
// Read the due date of the task
var taskDueDate = document.getElementById("taskDueDate").winControl;
task.dueDate = taskDueDate.current;
// Read the priority of the task
var taskPriority = document.getElementById("taskPriority");
task.priority = taskPriority.value;
// Read the status of the task
var taskStatus = document.getElementById("taskStatus");
task.status = taskStatus.options[taskStatus.selectedIndex].value;
// Read the percentage of the task completed
var taskPercCompleted = document.getElementById("taskPercCompleted");
Search WWH ::
Custom Search