aurelia / validatejs

Enables expressive validation using decorators and/or a fluent API.
MIT License
22 stars 23 forks source link

Custom-Renderer not merged to master #78

Closed cyberhck closed 8 years ago

cyberhck commented 8 years ago

I wanted to use custom renderer in my project which didn't work and just when I was about to kill myself, I found this diff: https://github.com/aurelia/validatejs/compare/custom-renderer#diff-1fdf421c05c1140f6d71444ea2b27638L1

Which indicates that custom renderer is not yet implemented in master. Please fix this ASAP Edit: for workaround you can do

    aurelia.use
        .plugin('aurelia-validatejs', config => {
            config.setRenderer(CustomRenderer);
        });

Then you should modify this in custom renderer file

import {DOM} from 'aurelia-pal';
import {ValidationRenderer} from "aurelia-validatejs";
export class CustomRenderer {
    static renderErrors(node, relevantErrors) {
        CustomRenderer.unrenderErrors(node);
        if (relevantErrors.length) {
            node.parentElement.classList.add('has-error');
            relevantErrors.forEach(error => {
                if (node.parentElement.textContent.indexOf(error.message) === -1) {
                    let errorMessageHelper = DOM.createElement('span');
                    let errorMessageNode = DOM.createTextNode(error.message);
                    errorMessageHelper.appendChild(errorMessageNode);
                    errorMessageHelper.classList.add('help-block', 'au-validation');
                    node.parentElement.appendChild(errorMessageHelper);
                }
            });
        }
    }
    static unrenderErrors(node) {
        let deleteThese = [];
        node.parentElement.classList.remove('has-error');
        let children = node.parentElement.children;
        for (let i = 0; i < children.length; i++) {
            let child = children[i];
            if (child.classList.contains('help-block') && child.classList.contains('au-validation')) {
                deleteThese.push(child);
            }
        }
        deleteThese.forEach(child => {
            node.parentElement.removeChild(child);
        });
    }
}
ValidationRenderer.prototype.renderErrors = CustomRenderer.renderErrors;
ValidationRenderer.prototype.unrenderErrors = CustomRenderer.unrenderErrors;
cyberhck commented 8 years ago

Did anyone notice this issue? Is anyone working on this? What's the status on this issue?

jdanyow commented 8 years ago

check out the blog post- it details the changes and includes a custom renderer example: http://blog.durandal.io/2016/06/14/new-validation-alpha-is-here/