-
Notifications
You must be signed in to change notification settings - Fork 55
add ability to "disable" form validity #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ability to "disable" form validity #203
Conversation
return; | ||
} | ||
ctrl.$setValidity('oscUnique', disabled); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just refer to $scope.oscUniqueDisabled
everywhere so we don't have two variables tracking the same value that could get out of sync. I think this could be a one-liner.
$scope.$watch('oscUniqueDisabled', function() {
ctrl.$setValidity('oscUnique', $scope.oscUniqueDisabled || isValid);
});
}, | ||
require: 'ngModel', | ||
link: function($scope, $elem, $attrs, ctrl) { | ||
var list = []; | ||
var disabled = false; | ||
var isValid = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest isUnique
here. It's technically valid if disabled even when not unique, so I think isUnique
is more accurate.
// if disabled, skip validation, return true | ||
if(disabled) { | ||
ctrl.$setValidity('oscUnique', disabled); | ||
return disabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this supposed to return the input value, not true
?
https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#$parsers
I think this can be
ctrl.$parsers.unshift(function(value) {
isValid = !_.includes(list, value);
ctrl.$setValidity('oscUnique', $scope.oscUniqueDisabled || isValid);
return value;
});
You could pull the $setValidity
line into its own function above so it's not repeated.
var isUnique = true;
var updateValiditity = function() {
ctrl.$setValidity('oscUnique', $scope.oscUniqueDisabled || isUnique);
};
$scope.$watch('oscUniqueDisabled', updateValidity);
ctrl.$parsers.unshift(function(value) {
isUnique = !_.includes(list, value);
updateValidity();
return value;
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for keeping this logic in the directive rather than the controller
49936dc
to
844fb58
Compare
@spadgett thanks for the feedback, review comments addressed |
…rwrite-option Automatic merge from submit-queue. add "overwrite" option to attachPVC view Depends on: openshift/origin-web-common#203 Fixes #2045 Work in progress. Just wanted to begin gathering feedback. Will post images. cc @spadgett @benjaminapetersen
Required by: openshift/origin-web-console#2176
Adds ability to disable form validity based on value of a model.