2016-03-21 7 views

答えて

0

角度形式では、watcher.listenerをフィールドに追加するだけで可能です。

ctrl.fields = [{ 
    key: 'lastname', 
    type: 'input', 
    templateOptions: { 
     label: 'Last name', 
     placeholder: 'Ex: PETERSON' 
    }, 
    watcher: { 
     listener: function(field, newValue, oldValue, formScope, stopWatching) { 
      console.log('watch lastname', arguments); 
      formScope.model.lastname = formScope.model.lastname.toUpperCase(); 
     } 
    } 
}, 
... 
0

だけでなく、単に入力フィールドにディレクティブを追加し、私はこれはくだらないものだった知っている私はformlyConfigProvider.setWrapperが得意ではないが、私は

angular 
    .module('myApp', []) 
    .directive('capitalize', function() { 
    return { 
     require: 'ngModel', 
     link: function(scope, element, attrs, modelCtrl) { 
     var capitalize = function(inputValue) { 
      if (inputValue == undefined) inputValue = ''; 
      var capitalized = inputValue.toUpperCase(); 
      if (capitalized !== inputValue) { 
      modelCtrl.$setViewValue(capitalized); 
      modelCtrl.$render(); 
      } 
      return capitalized; 
     } 
     modelCtrl.$parsers.push(capitalize); 
     capitalize(scope[attrs.ngModel]); // capitalize initial value 
     } 
    }; 
    }); 

入力データをautocapitaliseする良いディレクティブを持っていますしかし仕事は良いです

関連する問題