Skip to content

Instantly share code, notes, and snippets.

@imbalind
Created February 7, 2016 18:00
Show Gist options
  • Save imbalind/f92f12477b0839e6e712 to your computer and use it in GitHub Desktop.
Save imbalind/f92f12477b0839e6e712 to your computer and use it in GitHub Desktop.
Live validation thread
@imbalind
Copy link
Author

imbalind commented Feb 7, 2016

Some thoughts about @yccteam's live validation gitter:

  • I think the idea behind it is valid, I guess it cannot completely replace what we currently have but it's a very welcome integration.
  • we should design it so that it could be enabled/disabled by configuring the colDef since in my experience this is not a wanted feature, but I work with enterprise applications which are way different from your average web app, where I think this feature would be much needed.
  • it needs to be better integrated with validation AS-IS:
    • Different style: template vs directive approach, we should decide one.

      I'd rather move to directive style because it looks more "angular" and I think it should give better performance but I don't know if we could provide a behaviour like ng-class to add the $invalid class when validation fails after the user stops editing.
    • Messages (it could be a consequence of the style difference): if I can see the red cell when I'm typing, I'd like a way to know what's wrong.

      To answer the question in your code: actually the only way to know which validations failed, would be to scan the row entity for any field starting with '$$errors'+colDef.name, we could think about adding something to the row too, like an array or a property.
  • function addValidator will need to be customized for any element (maybe a decorator to use with custom template?)
  • why add a function to $parsers that calls a validator? I'd add a validator to $validators
  • I don't really like the while cycle inside liveValidator's link function, but I don't actually know whether there's a better way around it or not.

@YonatanKra
Copy link

Thanks @imbalind. Here are my 2 cents:

  • I agree with most of your points. It was never meant to replace your validator - only enhance it. What I've sent is a POC. It works along with your great validator, and adds the live edit to it as well as the integration with ngForm (in my app the grid (or several of them) are a part of a bigger form).
  • I'm working with enterprise apps only, and they expect this behavior (I've created something somewhat similar in my own app, but really liked your validator so decided to go along :)).
  • Enable/disable is definitely a must with every feature, and I think for every column as well. Not every column needs live validation.
  • I've used the $parser because it handles live edit of the input the "angular" way, without adding a new $watch.
  • Regarding how to know which validations failed - I think you could return the promises from the runValidators method, so anyone using it could tell what has failed "live" (I'm using a timeout there, but it's bad practice - promises are much more reliable).
  • the addValidator assumes you are using an input to edit. Is there another scenario in which you would like live editing?
  • I also don't like the while there. Any good ideas on how to get the cell element without it? I think that jQuery's solution (parentsUntil) works roughly the same...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment