Enable input insert [type = 'date']?

It seems like <input type='date' />you can't paste in Chrome. I tried all kinds of formats, including yyyy-MM-dd MM / dd / yyyy and even just inserting one component at a time (only a month or only a year), but nothing happens. I am working in an angular application, and even tried setting up the event onpasteto insert the inserted content into the angular model, but it never fires.

Here is what I have:

HTML

<input date-field type='date' ng-model='dateOfBirth'/>

Angular Directive:

'use strict';

angular.module('angularcoreApp').directive('dateField', function($filter) {
  return {
      require: 'ngModel',
      link: function(scope, element, attrs, ngModelController) {
        element[0].addEventListener('paste', function () {
          debugger;
          alert(arguments);
        }, false);
        ngModelController.$parsers = [];
        ngModelController.$parsers.push(function(data) {
          //View -> Model
          var date = Date.parseExact(data, "yyyy-MM-dd");
          ngModelController.$setValidity('date', date!=null);
          return date;
        });
        ngModelController.$formatters = [];
        ngModelController.$formatters.push(function(data) {
          //Model -> View
          return $filter('date')(data, "yyyy-MM-dd");
        });
       }
    }
});

I also import the date.

Currently, I never hit the statement debuggerin the insert event listener. An error does not occur, and it does not seem that any value is entered into the view or model.

How can I allow date entry on this entry?

+4
1

2016 .

<div id="wrapped" onpaste="alert(11)">
    <input type="date" id="input1">
</div>

, div "", .

0

Source: https://habr.com/ru/post/1606619/


All Articles