Search code examples
javascriptangularjshtmlhtml-input

Set default value for arrows in input[number]


I have an input type="number" for selecting a year that should load empty:

<input type="number" placeholder="Select year" min="1930" max="2015" required
   ng-custom-mask="9999" />

When the user selects the year by arrow keys, it starts in min value: 1930. It'd like something like 1980.

How do I set the custom "start" number to input[number]?

(Any HTML5, JavaScript (even AngularJS) would be nice...)


Solution

  • What about something like:

    HTML:

      <input 
         type="number" 
         placeholder="Select year" 
         min="1930" 
         max="2015" 
         required 
         ng-custom-mask="9999"
         ng-model="points" 
         step="{{getStep()}}" />
    

    In your controller:

      $scope.getStep = function() {
        if (!$scope.points) {
          return 50;
        }
        return 1;
      }