Code Monkey home page Code Monkey logo

Comments (6)

whatgoodisaroad avatar whatgoodisaroad commented on May 31, 2024

Hi!

This section of the documentation should explain how to invoke validity manually. http://validity.thatscaptaintoyou.com/Demos/index.htm#UsingValidityWithAjax

from validity.

mauriciocgpereira avatar mauriciocgpereira commented on May 31, 2024

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.

whatgoodisaroad avatar whatgoodisaroad commented on May 31, 2024

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.

mauriciocgpereira avatar mauriciocgpereira commented on May 31, 2024

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.

mauriciocgpereira avatar mauriciocgpereira commented on May 31, 2024

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.

whatgoodisaroad avatar whatgoodisaroad commented on May 31, 2024

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)

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.