Comments (2)
Anyone have solution for this issue. I'm too facing the same issue.
Thanks,
Settu Gowtham
from jqbootstrapvalidation.
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)
- Destroy undoes validations
- I use jquery ui to change the selectmenu,how can i to validate the selectmenu?
- Pattern
- Warning Don't Show
- jqBootstrapvalidation callback validation function not working after form validation
- filter does not affect "required" item
- Deprecated dependency "jQuery" in package.json
- jsBootstrapValidation it's not working with Bootstrap-select HOT 1
- The email [email protected] is correct? HOT 1
- Not working properly with jQuery > 1.7.2 HOT 2
- Remove wrong Comments
- Please add to JSDelivr HOT 1
- Not required Select menu tag have a red borde HOT 1
- Regex not working, input is never seen as valid
- i have two issues with the jqBootstrapValidation
- Validation field depending respect another 2 fields
- An email address with a TLD longer than four letters (like ".today") is marked invalid
- Dynamic Validate Problem
- How to make it work in modal
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jqbootstrapvalidation.