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.
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?