resthub / resthub-backbone-stack

RESThub Backbone.js stack
http://resthub.org/docs/backbone/
Other
56 stars 26 forks source link

Backbone validation extension (backbone-validation-ext.js) : show & hide text error #119

Closed pierre-duchesne closed 11 years ago

pierre-duchesne commented 11 years ago

I think it would be great to call the jquery hide function on the .help-inline element when the model is valid and call the jquery show function on this element when thes model isn't valid.

I think it's better to not reserve the space of the .help-inline element when there is no error.

What do you think about that ?

eg :

    valid: function(view, attr, selector) {
        // find matching form input and remove error class and text if any
        var attrSelector = '[' + selector + "~=" + attr + ']';
        // get the control group element
        view.$(attrSelector).closest('.control-group').removeClass('error');
        // get the controls element
        view.$(attrSelector).closest('.control-group').find('.help-inline').text('');            
        view.$(attrSelector).closest('.control-group').find('.help-inline').hide();
    },
    invalid: function(view, attr, error, selector) {
        // find matching form input and add error class and text error
        var attrSelector = '[' + selector + '~=' + attr + ']';
        // get the control group element
        view.$(attrSelector).closest('.control-group').addClass('error');
        // get the controls element
        view.$(attrSelector).closest('.control-group').find('.help-inline').text(error);
        view.$(attrSelector).closest('.control-group').find('.help-inline').show();
    }
bmeurant commented 11 years ago

why not ...display none or hide/show is only matter of choice and could be overrided if needed by projects. We could switch by default to show/hide version ...