Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Julien Enselme
    @Jenselme
    I doubt my solution scales thought. But for my test app with aurelia-validation it is enough. I hope we will have a better way to do this soon.
    Doug Kent
    @dkent600
    @Jenselme Since you are validating in attached, it seems like the message would show then. Also, I"m curious why you need the ol.getObserver thing. Doesn't the validator get automatically used on change or blur?
    Julien Enselme
    @Jenselme
    I use a Validator in attached. This won't display any message unlike the validate method of ValidationController. Since I need to rely on that to enable/disable my button, I have to watch if the title is changed to do a manual validation. I guess I should add these precision to my post.
    Doug Kent
    @dkent600
    @Jenselme OK, I think then your validateTrigger should be "manual". But the thing is, you are displaying titleErrors -- why isn't that showing an error message after you validate in attached?
    Julien Enselme
    @Jenselme

    Because titleErrors are managed by the ValidationController not the Validator. From the doc

    When you use a Validator directly to validate a particular object or property, there are no UI side-effects- the validation results are not sent to the the validation renderers.

    Doug Kent
    @dkent600
    @Jenselme Ah! I get it. OK, can you leave the trigger at "changeOrBlur" and remove the ol.getObserver? Then your validator would be invoked on change or blur. and you have a more scalable solution. what do you think?
    Julien Enselme
    @Jenselme

    I tried changing the code to this:

            this.validator.validateTrigger = validateTrigger.changeOrBlur;
    
            /*ol.getObserver(this.todo, 'title').subscribe(() => {
                this.validate();
            });*/

    But this has no effect: this.validator.validateObject is never called. Maybe I am missing something to correctly use trigger with Validator?

    Doug Kent
    @dkent600
    @Jenselme OK, sorry, I assumed something that wasn't happening -- I assumed you were telling the controller to use your validator. But you're not. But if you were then you'd see your validater being invoked.
    @Jenselme Try passing in your validator to controllerFactory.createForCurrentScope()
    Julien Enselme
    @Jenselme
    @dkent600 I guess it will be called yes. I tried this but without surprise my canSave property is not updated. And from the Validator interface I see no way to hook on the validation to call a cb.
    Doug Kent
    @dkent600
    @Jenselme well, I'm surprised that canSave wasn't updated unless typescript isn't getting the this right. What was the problem?
    @Jenselme oh, I get why
    @Jenselme Seems like you could create your own implementation of Validator, containing the instance of StandardValidator that you got from DI....
    Julien Enselme
    @Jenselme

    @dkent600 this could be the way! I am trying to implement it:

    class MyValidator {
        constructor(validator, cb) {
            this.validator = validator;
            this.cb = cb;
        }
    
        validateProperty(object, propertyName, rules) {
            this.validator.validateProperty(object, propertyName, rules);
        }
    
        validateObject(object, rules) {
            return this.validator.validateObject(object, rules).then(results => {
                this.cb(results);
                return results;
            });
        }
    
        ruleExists(rules, rule) {
            return this.validator(rules, rule);
        }
    }

    sadly I get a strange error:

    Uncaught (in promise) TypeError: Cannot read property 'slice' of undefined
        at ValidationController.processResultDelta (validation-controller.js:243)
        at eval (validation-controller.js:190)

    Don't see why.

    @dkent600 It's getting late. I have to go. I'll try again tomorow and keep you posted on what I find.
    Fernando Vega
    @vegafx12
    Hiya folks! Just trying out the Aurelia-Validator for the first time and I'm wondering if there's a default set of Validation messages defined somewhere in any of the .js/d.ts files? If so, I cannot find them :(
    Martin Johansson
    @kvadd
    That's an awesome catch @dkent600 I didn't know about the with.bind command. But, it's like you said, it doesn't feel like it should be necessary
    Christian Genne
    @genne
    Hi! Does the binding behavior validateOnChange work? I've tried using it but get the error "No BindingBehavior named "validateOnChange" was found!" (using the latest version)... also, can't see the code for it anywhere in GitHub?
    Fernando Vega
    @vegafx12
    @genne seems to be working okay for me... Although, I'm not calling a method...
    constructor(authService: AuthService, controller: ValidationController) {
            // Aurelia-Authentication
            this.authService = authService;
            this.authService.authenticated = false;
    
            // Aurelia-Validation
            this.controller = controller;
            this.controller.validateTrigger = validateTrigger.change;
    ....
    Christian Genne
    @genne
    @vegafx12 yes, that works for me as well! but using the binding behavior doesn't...
    Fernando Vega
    @vegafx12
    @genne What are you trying to do? I think I may be having the same (or at least similar) issue right now...
    Christian Genne
    @genne
    I need to use the change trigger for some specific elements (custom elements actually)... using the default blur event doesn't work as the custom element doesn't trigger blur correctly
    Or is there some other recommendations around how to use validation with custom elements?
    Fernando Vega
    @vegafx12
    @genne Have you tried using custom renderer?
    Christian Genne
    @genne
    Yes, we're using a custom rendered (for Bootstrap) so the rendering works fine
    Actually just solved it by triggering a blur event in the custom element using dispatchEvent. Still a bit weird that validateOnChange doesn't work though.
    Martin Johansson
    @kvadd
    @genne are you sure you are using the latest version of validation?
    I had that problem before, but that was because I was sitting on 0.12 of validation
    you'll need to update it in both npm AND jspm
    Christian Genne
    @genne
    hm, that might be the issue then, I only updated using jspm
    Martin Johansson
    @kvadd
    I did that exact thing as well at first :D
    you might even have to remove it first, and then updating it
    and, run NPM first and then JSPM
    Christian Genne
    @genne
    i see, i'll try that :thumbsup:
    Martin Johansson
    @kvadd
    you can check what version you are running in the package.json
    Fernando Vega
    @vegafx12
    I'm confused by something here.. I have in my view model's constructor a variable "this.errCount = this.controller.errors;" and in my view a simple bind to this variable "<p value.bind="errCount">${errCount}</p>"
    Christian Genne
    @genne
    @kvadd what version should i be running? :wink:
    Martin Johansson
    @kvadd
    aurelia-validation@^1.0.0-beta.1.0.1 is the latest
    Fernando Vega
    @vegafx12
    As I fille out my form, validation errors are created (because the rules are not yet me), and I can see the error messages rendered on screen... But if I change errCount to "this.errCount = this.controller.errors.length" the value displays "0", but does not change as I generate validation errors...
    Any thoughts on this one, guys?
    Martin Johansson
    @kvadd
    Why not just putting it straight into the view?
    ${controller.errors.length}
    Fernando Vega
    @vegafx12
    Well, that works! Hmm... why wouldn't the other way work though...? I must be confused about something :-\
    Martin Johansson
    @kvadd
    it sounds like it loses binding somehow
    depending on where you set the value, it sets it like that right there and then, and don't update when the value changes
    Fernando Vega
    @vegafx12
    Interesting... oh well. I've got it going now! Thanks! :)
    Martin Johansson
    @kvadd
    @dkent600 I got an amazing followup issue with the repeat.for and validation binding now :D
    The issue is with the .required(), since it's not actually checking correctly with a string that's "". It's looking at it, but no longer recognizing that's it is empty if you have it inside a repeat.for
    Fernando Vega
    @vegafx12
    hmmmm so I have button disabled on page load... I only want the button to be active after all fields have passed validation. Is there a way to check each field "Is Validated"?