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

Override $isEmpty is bugged #116

Open
ollivierv opened this issue Nov 26, 2015 · 1 comment
Open

Override $isEmpty is bugged #116

ollivierv opened this issue Nov 26, 2015 · 1 comment

Comments

@ollivierv
Copy link

The overrided function to support empty array is bugged.
If the value is NOT an array or string but a number, the function return true, but ... it's not empty !

Because evaluate of "!(123).length" is "true" !

In addition, $isEmpty from Angular is lost by override, and it's a very bad idea. We must keep this function for next evolution.

I made a quick fix by a new function :

function isEmpty2(val, modelCtrl)
{
    if( $.isArray(val) )
        return (val.length > 0) ? false : true;
    return modelCtrl.$isEmpty(val); //call to real Angular function
}

And rewrite call in Validate() function :

var validate = function() {
    var isInvalid = (scope.ngRequired() || attrs.required || config.required) && isEmpty2(scope.ngModel,modelCtrl);
    modelCtrl.$setValidity('required', !isInvalid);
};
@PhiLhoSoft
Copy link
Contributor

Related to #110

Note that modelCtrl.$isEmpty has been removed in a previous commit.

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

No branches or pull requests

2 participants