Numeric keypad 8 and 9 crashes app - KnockoutJS + Cordova

爷,独闯天下 提交于 2019-12-12 02:13:17

问题


I am facing a strange issue in my project. I have used KnockoutJS for creating my UI. I am using latest version of Android Cordova. I have defined an HTML input type number in KnockoutJS

    <input maxlength="3" type="number" data-bind="maxLength: maxLengthSeats" placeholder="seats" />

However, when I run my app on Android device, the numeric keypad opens but when I enter either 8 or 9, my app crashes. There are no errors or logs. The app just stops with a white screen and I see the home screen of my device.

Why is the problem coming? I tried creating a fresh new Cordova project and added just one input number which is working. So what's the issue with Knockout ?

Has anyone faced such a problem when using Knockout in combination with cordova?

 //truncate value extender
  ko.extenders.truncateValue = function(target, option) {                            
  target.subscribe(function (newValue) {
      if(newValue.length > option){
          target(newValue.substring(0,option));
      }                    
   });

   return target;
};

 //maximum length extender
  ko.bindingHandlers.maxLength = {
   init:  function (element, valueAccessor, allBindingsAccessor,      
    viewModel) {
      'use strict';                     

      var maxlength = element.getAttribute("maxlength");

      valueAccessor().extend({truncateValue: maxlength })
      ko.bindingHandlers.value.init(element, valueAccessor,     
   allBindingsAccessor, viewModel);    
  }   
};

来源:https://stackoverflow.com/questions/42736659/numeric-keypad-8-and-9-crashes-app-knockoutjs-cordova

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!