0

what is the most angular way to capitalize an input on blur?

my view code:

<input name="initials" type="text" ng-model="vm.initials" minlength="2" maxlength="4" ng-blur="vm.capitalizeInitials()"

my controller code:

vm.capitalizeInitials = function(){
      vm.initials = angular.uppercase(vm.initials);
    }

Is there a better way to do it?

devdropper87
  • 4,025
  • 11
  • 44
  • 70
  • Take a look at this link, it may help you: [Angular force uppercase in textbox](http://stackoverflow.com/questions/16388562/angularjs-force-uppercase-in-textbox) – miquelarranz May 25 '16 at 14:50
  • As per miquelarranz's link, you could write a directive that capitalizes the input on entry. Alternatively, you could use CSS to capitalize the input field, then simply run ``.uppercase`` when the data is saved. The prior is the more "angular" way, though the later is certainly easier. – Alex Johnson May 25 '16 at 14:54
  • I'm thinking of doing the 'easiest' way: – devdropper87 May 25 '16 at 14:56

1 Answers1

0

You can use both of them, if you are looking for the easiest and fastest way use the solution that you're saying.

<input name="initials" type="text" ng-model="vm.initials" minlength="2" maxlength="4" ng-blur="vm.initials = vm.initials.toUpperCase()">
miquelarranz
  • 876
  • 11
  • 26