Book Image

KNOCKOUTJS BLUEPRINTS

By : Carlo Russo
Book Image

KNOCKOUTJS BLUEPRINTS

By: Carlo Russo

Overview of this book

Table of Contents (12 chapters)
KnockoutJS Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Refactoring and working on the missing parts


The code for the Account CRUD is done and working, right? Or maybe there is something not working perfectly, caused from jQuery Mobile Widget enhancement?

Fixing KnockoutJS binding handler inside jQuery Mobile

If you create an Account with the type bank, and then you try to edit it, you'll see the cash type selected in the select field.

The reason behind this bug is that jQuery Mobile enhances the form components modifying the DOM structure, so you have to fix how the KnockoutJS binding handlers work in a few cases (like the value).

In this case, we have to modify the binding handler value to make it work with select; let's create www/app/binding-handlers/selectValue.js:

define(function (require) {
  var ko = require("knockout"),
      $ = require("jquery");

  ko.bindingHandlers.selectValue = {
    init: function (element, valueAccessor) {
      var value = valueAccessor(),
          $element = $(element);

      ko.bindingHandlers.value.init.apply...