GithubHelp home page GithubHelp logo

Comments (2)

settugowtham avatar settugowtham commented on July 17, 2024

Anyone have solution for this issue. I'm too facing the same issue.

Thanks,
Settu Gowtham

from jqbootstrapvalidation.

bosborn52 avatar bosborn52 commented on July 17, 2024

I don't know if this helps anyone, but I wanted a way to validate preloaded forms that are dynamically loaded with ajax. I added another function to the source code by stealing parts of the init function. This probably isn't the right way, but it worked.

            isValid: function(options) {
                var
                    $this = $(this),
                    $controlGroup = $this.parents(".form-group").first(),
                    $helpBlock = $controlGroup.find(".help-block").first(),
                    $formControl = $this,
                    errorsFound = [],
                    value = getValue($this),
                    settings = $.extend(true, {}, defaults);

                settings.options = $.extend(true, settings.options, options);
                // create message container if not exists
                if (!$helpBlock.length && settings.options.autoAdd && settings.options.autoAdd.helpBlocks) {
                    $helpBlock = $('<div class="help-block" />');
                    $controlGroup.append($helpBlock);
                    createdElements.push($helpBlock[0]);
                }

                console.log($controlGroup)

                $controlGroup.find("input,textarea,select").each(function(i, el) {
                    var oldCount = errorsFound.length;
                    $.each($(el).triggerHandler("validation.validation") || [], function(j, message) {
                        errorsFound.push(message);
                    });
                    if (errorsFound.length > oldCount) {
                        $(el).attr("aria-invalid", "true");
                    } else {
                        var original = $this.data("original-aria-invalid");
                        $(el).attr("aria-invalid", (original !== undefined ? original : false));
                    }

                    errorsFound = $.unique(errorsFound.sort());

                    // Were there any errors?
                    if (errorsFound.length) {
                        // How many errors did we find?
                        if (settings.options.semanticallyStrict && errorsFound.length === 1) {
                            // Only one? Being strict? Just output it.
                            helpDiv = '<div class="mb-10 alert alert-custom alert-light-warning alert-dismissible" role="alert">\
                                            <div class="alert-text font-weight-bold ">' + errorsFound[0] + '</div>\
                                            <div class="alert-close">\
                                                <i class="ki ki-remove" data-dismiss="alert"></i>\
                                            </div>\
                                        </div>'
                            $helpBlock.html(helpDiv +
                                (settings.options.prependExistingHelpBlock ? $helpBlock.data("original-contents") : ""));


                        } else {
                            helpDiv = '<div class="alert alert-custom alert-light-danger alert-dismissible" role="alert">\
                                <div class="alert-text font-weight-bold ">' + "<ul role=\"alert\"><li>" + errorsFound.join("</li><li>") + "</li></ul>" + '</div>\
                                <div class="alert-close">\
                                    <i class="ki ki-remove" data-dismiss="alert"></i>\
                                </div>\
                            </div>'
                            $helpBlock.html(helpDiv +
                                (settings.options.prependExistingHelpBlock ? $helpBlock.data("original-contents") : ""));
                        }
                    } else {
                        $controlGroup.removeClass("warning error success");
                        $formControl.removeClass("is-valid is-invalid");
                        if (value.length > 0) {
                            $controlGroup.addClass("success");
                            $formControl.addClass("is-valid");
                        }
                        $helpBlock.html($helpBlock.data("original-contents"));
                    }
                });
            },

To call it in my use case:

function showEditModal(data) {
    editProjectionForm(data)

    $('#edit-modal').modal('show');
    modal = $('#edit-modal')
    modal.one('shown.bs.modal', function() {
        var form = $(this).find('.modal-content form').closest("form")[0];

        for (var i = 0; i < form.elements.length; i++) {
            var e = form.elements[i];
            console.log(e.id)
            $('#' + e.id + '').jqBootstrapValidation("isValid")

        }
    }).one('hidden.bs.modal', function() {
        $("#form-div").empty();
    });

}

from jqbootstrapvalidation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.