Sha256: 31aa2da032caa23ad273b95e25a6c2a192ec9ce11c3ee5bf98f89f6ce43e69e2

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

/**
 * Created by scout on 3/25/15.
 * "методы" по работе с модальными окнами.
 *
 */

(function($) {

    $.fn.modal_success = function(){
        //console.log("modal_success>");

        // close modal
        this.modal('hide');

        // clear form input elements
        this.find('input[type="text"]').val('');
        this.find('textarea').val('');

        // clear error state
        this.clear_previous_errors();
    };

    $.fn.render_form_errors = function(errors){

        var $form = this;
        this.clear_previous_errors();
        var model = this.data('model');

        // show error messages in input form-group help-block
        $.each(errors, function(field, messages){

            var $input = $('input[name="' + model + '[' + field + ']"]');
            if ($input.length == 0) {
                $input = $('textarea[name="' + model + '[' + field + ']"]');
            }

            $input.closest('.form-group')
                .addClass('has-error')
                .find('.help-block')
                //.html( messages.join('  ') );
                .html( messages[0] );
        });

    };

    $.fn.clear_previous_errors = function(){
        $('.form-group.has-error', this).each(function(){
            //console.log($('.help-block', $(this)));
            $('.help-block', $(this)).html('');
            $(this).removeClass('has-error');
        });
        $.rails.enableFormElements($(this));
    };

    $.fn.my_render_form_errors = function(errors) {

        var model = this.data('model');

        $.each(errors, function(field, messages) {

            var $span = $('span#' + model + '_' + field);
            //console.log($span);
            $span.closest('.form-group').addClass('has-error');
            $span.html( messages.join(' & ') );

        });

    };

}(jQuery));

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
c80_modal_forms-0.1.0.2 app/assets/javascripts/modal_forms.js
c80_modal_forms-0.1.0.1 app/assets/javascripts/modal_forms.js