Ho riscontrato un problema con il posizionamento del cursore quando si utilizza l'autofocus in IE. L'immagine dovrebbe mostrare chiaramente il problema.Strana collocazione del cursore in modalità modale quando si utilizza la messa a fuoco automatica in Internet Explorer
Per fortuna sono stato in grado di riprodurre questo in un plunker. L'ho ridotto all'essenziale, quindi dovrebbe essere abbastanza facile vedere cosa sta succedendo.
Come faccio a comportarmi con IE?
AngularJS (anche nelle plunker)
app.directive('autofocus', [
'$timeout', function($timeout) {
return function(scope, elem, attr) {
scope.$on('autofocus', function(e) {
$timeout(function() {
elem[0].focus();
});
});
};
}
]);
/* http://stackoverflow.com/questions/14833326/how-to-set-focus-in-angularjs */
app.factory('autofocus', ['$rootScope', '$timeout', function($rootScope, $timeout) {
return function() {
$timeout(function() {
$rootScope.$broadcast('autofocus');
});
};
}]);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('main', {
url: '/main'
});
}]);
app.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('main.modal', {
url: '/modal',
onEnter: ['$state', '$stateParams', '$modal', 'autofocus',
function ($state, $stateParams, $modal, autofocus) {
var instance = $modal.open({
templateUrl: 'modal.html'
});
instance.result.then(function() {
// OK
// GOTO parent state
$state.go('^');
}, function() {
// Cancel
// GOTO parent state
$state.go('^');
});
instance.opened.then(function() {
autofocus();
});
}
]
});
}]);
Markup
<form>
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<input type="text" name="foo" autofocus>
<br>
<input type="text" name="bar">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">OK</button>
<button type="button" class="btn btn-warning" ng-click="$dismiss()">Cancel</button>
</div>
</form>
Non so perché qualcuno dovrebbe mettere un -1 su questo, perché in realtà ha funzionato per me. In realtà è meglio che fornire una classe personalizzata per ogni modal che devo aprire in ogni controller. – Aureliink
Ho lavorato per me due anni dopo, grazie! – ClaytonAlanKinder