import UiSelectContainer from './services/ui_select_container';
angular.module('app', [UiSelectContainer.name])
Last active
August 26, 2016 09:37
-
-
Save shenqihui/514ea870485e0d209ba12c98a549924a to your computer and use it in GitHub Desktop.
ui select need to focus invalid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import angular from 'angular'; | |
export default angular.module('services.uiSelectContainer', []) | |
.directive('uiSelectContainer', function () { | |
return { | |
priority: -1, | |
restrict: 'C', | |
require: 'ngModel', | |
link ($scope, $element, $attrs) { | |
let $input = $element.find('input').eq(1); | |
let requiredFunc = () => {}; | |
let ngModel = $attrs.ngModel; | |
if ($input.hasClass('ui-select-offscreen')) { | |
requiredFunc = () => { | |
let isRequired = $scope.$eval($attrs.ngRequired) || false; | |
if (('' === $scope.$eval(ngModel) || undefined === $scope.$eval(ngModel)) && isRequired) { | |
$input.attr('required', isRequired); | |
} | |
else { | |
$input.removeAttr('required'); | |
} | |
}; | |
$attrs.$observe('required', () => { | |
requiredFunc(); | |
}); | |
$scope.$watch(ngModel, () => { | |
requiredFunc(); | |
}); | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment