by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Doug Kent
    @dkent600
    so it partly depends on exactly what you want to feed back to the user
    one thing you can do is have two controllers, or mess around with swapping renderers on a single controller, and have two validation paths, one that validates per field and displays feedback per field, and one that validates the entire object, without visual feedback, to set the disabled state on your button.
    Julien Enselme
    @Jenselme
    The two controllers may solve my problem. I am doing some tests with manual validation in attached: I can get a canSave property to false initially. My problem is: how can I detect that validation has run again to update this value and allow the user to submit the form?
    I should just reuse validation-errors.bind="errors": the array is filled correctly initially
    Doug Kent
    @dkent600

    You can make controller.errors observable, a bit of a hack IMHO, or, the currently proposed best method is to implement your own ValidationRenderer whose render method is invoked whenever validation occurs.

    There is a long unresolved discussion of this, here: aurelia/validation#318

    Feel free to add your support to implementing something there....

    Yes, you could observe your errors property
    on second thought, I'm not sure how observing the errors properties (yours or the controller's) helps you know when validation has occurred, nor in knowing whether the entire form is valid.
    may it ^^^ could help in just knowing whether validation has changed
    Julien Enselme
    @Jenselme

    You can make controller.errors observable

    I tried that without success.

    I am trying to obtain the behaviour I want with two controllers. I'll also look at the link you posted.

    Doug Kent
    @dkent600
    cool
    Doug Kent
    @dkent600
    @kvadd Sorry, make that: <div class="form-group" repeat.for="field of fields" with.bind="$parent">
    Julien Enselme
    @Jenselme
    @dkent600 I didn't manage to use two controllers but I found a work around with one controller and a validator. More details in this blog post: http://www.jujens.eu/posts/en/2017/Jan/24/aurelia-validation/
    Doug Kent
    @dkent600
    @Jenselme How do you manage to prevent the error message for the title from displaying too soon?
    Julien Enselme
    @Jenselme
    @dkent600 I do. The message is displayed by the controller (normal usage) and the button is managed by the validator.
    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