在 Bootstrap UI 中,单击日期时日期选择器焦点不会返回到日期字段
In Bootstrap UI datepicker focus is not returning back to the date field when clicked on a date
当我点击 Today, clear
或 close
按钮时,焦点返回到 date field
。
当我点击任何特定日期时,我想要相同的功能。
我调试了这个问题。发现在日期选择器本身中,一旦选择了日期,就无法将焦点恢复到日期字段。
日期选择器弹出窗口: http://angular-ui.github.io/bootstrap/
发现在文件:datepicker.js 中,当我们点击任何日期时,函数 $scope.select = function(date)
会被触发,而该日期又会广播一个未被捕获的事件 $scope.$broadcast('uib:datepicker.focus');
我们代码中的任何位置。
下面是修复的代码:
var focusElement = function() {
self.element[0].focus();
};
// Listen for focus requests from popup directive
$scope.$on('uib:datepicker.focus', focusElement);
Link 有帮助:https://github.com/angular-ui/bootstrap/blob/master/src/datepicker/datepicker.js#L213
当我点击 Today, clear
或 close
按钮时,焦点返回到 date field
。
当我点击任何特定日期时,我想要相同的功能。
我调试了这个问题。发现在日期选择器本身中,一旦选择了日期,就无法将焦点恢复到日期字段。
日期选择器弹出窗口: http://angular-ui.github.io/bootstrap/
发现在文件:datepicker.js 中,当我们点击任何日期时,函数 $scope.select = function(date)
会被触发,而该日期又会广播一个未被捕获的事件 $scope.$broadcast('uib:datepicker.focus');
我们代码中的任何位置。
下面是修复的代码:
var focusElement = function() {
self.element[0].focus();
};
// Listen for focus requests from popup directive
$scope.$on('uib:datepicker.focus', focusElement);
Link 有帮助:https://github.com/angular-ui/bootstrap/blob/master/src/datepicker/datepicker.js#L213