Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

"minValidator" does not make sense as a formatter. Input number "min" does not show initial value when it is invalid #8264

Closed
yogeshgadge opened this issue Jul 18, 2014 · 4 comments

Comments

@yogeshgadge
Copy link

Problem

Initial invalid values are lost in the Form when $dirty is false.

http://jsfiddle.net/PK3QH/7/

Scenario

You are displaying a Form intending to show fields with proper validation e.g. min=10 for .

The model returns a number 3 as what was probably saved prior say in some database. Or your business rules have changed and the min value now must be 10 but it was say min=2 in the previous release of your application.

Possible diagnosis

e.g.

minValidator
  if (attr.min) {
    var minValidator = function(value) {
      var min = parseFloat(attr.min);
      return validate(ctrl, 'min', ctrl.$isEmpty(value) || value >= min, value);
    };

    ctrl.$parsers.push(minValidator);
    ctrl.$formatters.push(minValidator); //I wonder if you really need this
    ///all you need is a number validator
  }

@caitp
Copy link
Contributor

caitp commented Jul 18, 2014

The fact is, none of the validation really belongs in parsers or formatters. Validation and parsing/formatting are really separate operations.

Anyhow, this is being worked on, thanks for sharing the pain of the current validation stuff =)

@IgorMinar IgorMinar self-assigned this Jul 21, 2014
@IgorMinar
Copy link
Contributor

@matsko can you add this as a test case to your refactoring branch and close this issue please?

@IgorMinar IgorMinar added this to the 1.3.0 milestone Jul 21, 2014
@IgorMinar
Copy link
Contributor

@yogeshgadge fyi, please watch #6928

@Narretz
Copy link
Contributor

Narretz commented Sep 5, 2014

This is fixed in master: http://jsfiddle.net/PK3QH/24/

This is won't fix in 1.2.x afaik, because validation via parsers is too rigid.

@Narretz Narretz closed this as completed Sep 5, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants