Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

fix(datepicker): validate using ng-required attribute #4002

Closed
wants to merge 4 commits into from

Conversation

nivivive
Copy link
Contributor

This is a solution for the the issue (#3862), where date is always required for datepicker, even when ng-required is set to false.

(todo: still need to add tests)

@nivivive
Copy link
Contributor Author

@wesleycho, moving the discussion to this PR:

In response to your comments, I had some questions. Would the proper fix be to:

  1. log the error: "Datepicker directive: "ng-model" value must be a Date object..." regardless of what ng-required is set as
  2. remove ngModelCtrl.$setValidity('date', ...) from this.render() and move all the validation logic to ngModelCtrl.$validators.date

@wesleycho
Copy link
Contributor

Correct on both counts

@wesleycho wesleycho modified the milestones: 0.13.2 (Performance), 0.13.x Jul 22, 2015
@nivivive
Copy link
Contributor Author

does this look good?

@@ -616,6 +615,11 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi

function validator(modelValue, viewValue) {
var value = modelValue || viewValue;

if (!attrs.ngRequired && !value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this even necessary? Does this run if ngRequired is falsy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works even if ngRequired is falsy. If ngRequired is falsy (i.e. anything other than ng-required=true), then the datepicker is not required. So, it considers an empty value valid in that case, but will check for date validity for any non-empty value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't saying just working - I was wondering whether the validator even runs if !attrs.ngRequired. If it doesn't run, it wouldn't be necessary, but if it does, then this line is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validator does run if !attrs.ngRequired

@wesleycho
Copy link
Contributor

This LGTM, I will do a full check on Sunday and hopefully will merge it in shortly after.

@wesleycho wesleycho self-assigned this Jul 24, 2015
@nivivive
Copy link
Contributor Author

hey, is there any update on this?

@wesleycho
Copy link
Contributor

Sorry, haven't had the chance to check this out yet, as it requires a little more setup/evaluation than the other stuff I have looked at so far.

I do intend on reviewing this thoroughly this week though.

@wesleycho
Copy link
Contributor

Looks good here.

@wesleycho wesleycho closed this in fe0d954 Jul 29, 2015
@wesleycho wesleycho modified the milestones: 0.13.2 (Performance), 0.13.x Jul 29, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants