1

I'm using Bootstrap's datepicker in my application. when I press the PrtScrn key on my keyboard it changes the year in the datapicker.

How can I stop this behavior from happening?

Here is my Directive code.

 .directive('datepicker', function(){
        return {
            require: '?ngModel',
            restrict: 'A',
            link: function(scope, element, attrs, ngModel,$filter){
                 var dates = scope.$eval(attrs.datepicker);               
                if(dates[0].toDate !== null)
                {
                  var date =new Date(dates[0].toDate) ;
                  var toDate=(date.getDate()) + '/' + (date.getMonth() + 1)+ '/' +  date.getFullYear();
                  var date1 =new Date(dates[0].fromDate) ;
                  var fromDate=(date1.getDate()) + '/' + (date1.getMonth() + 1) + '/' +  date1.getFullYear();
                }                
                if(!ngModel) return; // do nothing if no ng-model

                ngModel.$render = function(){

                    element.val( ngModel.$viewValue || '' );
                }

                element.datepicker({
                    format    : 'dd/mm/yyyy',
                    autoclose : true,
                    //startDate : toDate,
                    endDate   : toDate
                });            

                function read() {
                    var value = element.val();
                  //  ngModel.$setViewValue(value);
                }  
            }
        }
    });

This is html code

     <input 
    dynamic-name="field.name"
    datepicker="[{toDate:field.todate,fromDate :field.fromdate}]"                                                      readonly="field.isreadonly"
    type="text"
    placeholder ="{{field.placeholder}}"
    class="form-control"
    dynamic-validation = "field.validationtype"
    ng-model= "formVariables[field.name]"
    value="{{field.value}}"
    ng-required = "{{field.expression}}"
 />

Step to reproduce:

  • Click on month or year.
  • Then click right or left arrow of year.
  • Press PrtScrn key of keyboard and observe the output year and months get change.

Expected result year or Month should not be change when press PrtScrn key.

7
  • I've used Bootstrap's datepicker also, but in my project, your problem is not occurred.. Um.. so weird.. can you post your code of controller or html? Or is there some code using key event in your project? Oct 24, 2017 at 2:33
  • Thanks Canet Robern, i have updated my question with controller and html code .please check and let me know. Oct 24, 2017 at 5:20
  • Can you share the modules what you are using? Oct 24, 2017 at 5:26
  • I've tried your code in my fiddle jsfiddle.net/Canet/r757rswp but I cannot find any errors.. Have you edited or modified js files? Or do you have any key event in your local code? Oct 24, 2017 at 6:00
  • There is no any key event in my code. i've checked your jsfiddle.net/Canet/r757rswp but there is same problem occure. i'm using MAC or windows os . check this problem follow step. 1> click on month or year. 2> then click right or left arrow of year. 3> press PrtScrn key of keyboard and observe the output year and months get change . Expected result year or Month should not be change when press PrtScrn key. Oct 24, 2017 at 6:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.