Comments (6)
Hi!
This section of the documentation should explain how to invoke validity manually. http://validity.thatscaptaintoyou.com/Demos/index.htm#UsingValidityWithAjax
from validity.
Yes it helped, in a way :-)!
It works when the form is loaded via jquery, but for browsers with javascript disabled the form page loads directly, in this case I have to bind the form.
How can I "join" the two methods?
Thanks in advance
from validity.
I don't understand. If JavaScript is disabled, Validity won't work at all.
You can't bind to anything.
-wyatt
On Sun, Jun 30, 2013 at 9:57 AM, Mauricio Pereira
[email protected]:
Yes it helped, in a way :-)!
It works when the form is loaded via jquery, but for browsers with
javascript disabled the form page loads directly, in this case I have to
bind the form.How can I "join" the two methods?
Thanks in advance
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-20250383
.
from validity.
Sorry, that's not what I meant to say.
I meant that if the user goes directly to the page, instead of loading it thru jquery in the homepage, the form doesn't bind.
Sorry for my mistake... many hours working :-)
from validity.
Here is my code:
$("form").validity(function() {
$("#fullname")
.require("O Nome é obrigatório.")
.minLength(12, "O Nome deverá ser mais detalhado.");
$("#email")
.require("O Email é obrigatório.")
.match("email", "Deverá indicar um email válido.");
$("#assunto")
.require("Por favor seleccione um assunto");
$("#confirmacao")
.checkboxChecked("Por favor confirme que pretende enviar este email");
});
function validateMyAjaxInputs() {
// Start validation:
$.validity.start();
$("#fullname")
.require("O Nome é obrigatório.")
.minLength(12, "O Nome deverá ser mais detalhado.");
$("#email")
.require("O Email é obrigatório.")
.match("email", "Deverá indicar um email válido.");
$("#assunto")
.require("Por favor seleccione um assunto");
$("#confirmacao")
.checkboxChecked("Por favor confirme que pretende enviar este email");
var result = $.validity.end();
// Return whether it's okay to proceed with the Ajax:
return result.valid;
};
$.validity.setup({
// You may change the output mode with this property.
outputMode: "summary",
scrollTo: false,
modalErrorsClickable: true,
defaultFieldName: "This field"
});
function ajaxButtonClicked() {
if (validateMyAjaxInputs()) {
alert("na");
}
}
<!-- form validity end -->
<!-- history start -->
$(window).bind("load", function() {
if(Modernizr.history){
var everPushedSomething = false;
var newHash = "",
$mainContent = $("#content"),
baseHeight = 0,
$el;
$("#selectGoTo select").change(function() {
_link = $(this).val();
history.pushState(null, null, _link);
loadContent(_link);
everPushedSomething = true;
return false;
});
$("nav").on("click", "a", function() {
var _link = $(this).attr("href");
history.pushState(null, null, _link);
loadContent(_link);
everPushedSomething = true;
return false;
});
function loadContent(href){
$mainContent
.find("#contentDiv")
.fadeOut(400, function() {
$mainContent.hide().load(href + " #contentDiv", function() {
$mainContent.fadeIn(400, function() {
$("#navSubMenu").on("click", "a", function() {
var _link = $(this).attr("href");
//alert(_link);
history.pushState(null, null, _link);
loadContent(_link);
everPushedSomething = true;
return false;
});
if (href === "contactos.html") {
initialize();
//ajaxButtonClicked()
validateMyAjaxInputs();
} else {
};
});
});
});
}
$(window).bind('popstate', function(){
if (everPushedSomething) {
$.getScript(location.href);
_link = location.pathname.replace(/^.*[\\\/]/, ''); //get filename only
}
everPushedSomething = true;
loadContent(_link);
});
}
});
<!-- history end -->
How can I make the form work inthe both ways, via loading external content to a div thru jquery and by going directly to the form page.
Thanks in advance
from validity.
You can just run the validation code whenever the form is loaded into the DOM. It would work the same whether or not the form was added via ajax.
from validity.
Related Issues (20)
- Assert doesn't work properly on multiple calls (non-form, non-aggregate) HOT 6
- CSS classes to invalid inputs HOT 2
- optional field with validation dilemma HOT 3
- Problem with input type="number" HOT 6
- Changing validation rules on the fly HOT 1
- Preventing multiple submits of the form HOT 2
- Guideline checkboxes HOT 5
- Not working with Safari? HOT 1
- checkbox validation HOT 1
- How to Disable the Validator HOT 1
- Scrollto doesn't work when in modal outputmode
- how to make radio button require HOT 1
- Add to Bower
- Append validations to existing validation
- Is it possible to change CSS so that label's arrow lines up with the bottom of the input field? HOT 1
- Add a package.json npm manifest to root
- hide() / show() changed in jquery 3 - breaks summary output HOT 1
- How to display message over a related element?
- jsfiddle example of using validity with tooltipster
- Documentation Site not working anymore HOT 1
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 validity.