Skip to content
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

Merged

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Sep 26, 2017

Required by: openshift/origin-web-console#2176

Adds ability to disable form validity based on value of a model.

return;
}
ctrl.$setValidity('oscUnique', disabled);
});
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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;
});

Copy link
Contributor

@benjaminapetersen benjaminapetersen left a 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

@juanvallejo juanvallejo force-pushed the jvallejo/add-osc-unique-disabled-attr branch from 49936dc to 844fb58 Compare September 27, 2017 21:18
@juanvallejo
Copy link
Contributor Author

@spadgett thanks for the feedback, review comments addressed

@spadgett spadgett merged commit dc17969 into openshift:master Sep 28, 2017
@juanvallejo juanvallejo deleted the jvallejo/add-osc-unique-disabled-attr branch October 2, 2017 14:00
openshift-merge-robot added a commit to openshift/origin-web-console that referenced this pull request Oct 13, 2017
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants