{"id":3285,"date":"2011-03-14T01:58:36","date_gmt":"2011-03-13T20:28:36","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=3285"},"modified":"2011-03-14T02:26:08","modified_gmt":"2011-03-13T20:56:08","slug":"simple-client-side-ajax-validation","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/","title":{"rendered":"Simple Client Side Ajax Validation"},"content":{"rendered":"<div id=\"_mcePaste\">Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better .<\/div>\n<div id=\"_mcePaste\">One of those things was with jQuery.<\/div>\n<div id=\"_mcePaste\">Now working with a normal submit form, a <strong>jQuery Validate Plugin<\/strong> works superbly. You simply give<\/div>\n<div id=\"_mcePaste\">&#8220;<strong>class = required <\/strong>&#8220;<\/div>\n<div id=\"_mcePaste\">and it does the job.<\/div>\n<p>But when do the same with an Ajax call .. the Ajax call goes out without a validation.. which is what you don&#8217;t want. The call should only go out if the validation passes . Now faced with this I started to write a custom method &#8230; but on some reading up, found out that there actually exists a way to do this through the Plugin itself.<\/p>\n<div>The <strong>.form()<\/strong> method coupled with a <strong>.validate<\/strong> gives you a Boolean value i.e true if validated or false if not.<\/div>\n<p>Something like<\/p>\n<p><span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;\"> <\/span><\/p>\n<p>[javascript]<br \/>\nfunction validateForm() {<br \/>\n.<br \/>\n.<br \/>\n  if ($(&#8216;#form&#8217;).validate().form()) {<br \/>\n          \/\/ (Put your Ajax Call here)<br \/>\n    }<br \/>\n}<br \/>\n[\/javascript]<\/p>\n<div id=\"_mcePaste\">In this way the Ajax call went out only if the<strong> .validate().form()<\/strong> returned true.<\/div>\n<div id=\"_mcePaste\">Another usecase where I used it was when the whole form was when the whole form went through an Ajax call.<\/div>\n<div id=\"_mcePaste\">I used a <strong>&lt;g:formRemote&gt;<\/strong> tag . Now it doesn&#8217;t have a &#8216;<strong>onSubmit<\/strong>&#8216; of the normal form but it does have a &#8216;<strong>before<\/strong>&#8216; attribute that works somewhat similarly.<\/div>\n<div id=\"_mcePaste\">So now,<\/div>\n<p>[html]<br \/>\n&lt;g:formRemote name=&quot;searchPage&quot; id=&quot;searchPage&quot; url=&quot;${[controller:&#8217;eventInstance&#8217;,action:&#8217;executeSearch&#8217;]}&quot; update=&quot;searchUpdate&quot; before=&quot;return validateSearchForm()&quot;&gt;<br \/>\n.<br \/>\n.<br \/>\n&lt;\/g:formRemote&gt;<br \/>\n[\/html]<\/p>\n<p>With a Javascript function<\/p>\n<p>[javascript]<br \/>\nfunction validateSearchForm() {<br \/>\n    if ($(&#8216;#searchPage&#8217;).validate().form() &amp;&amp; checkDate()) {<br \/>\n      return true;<br \/>\n    }<br \/>\n    else {<br \/>\n      return false;<br \/>\n    }<br \/>\n  }<br \/>\n[\/javascript]<\/p>\n<p>So in this way the page would be Ajaxified if both of those methods returned true &#8230;<\/p>\n<p>Hope this helps ..<\/p>\n<p>Manoj Mohan<br \/>\n<strong>Manoj (at) Intelligrape (dot) com<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly. [&hellip;]<\/p>\n","protected":false},"author":32,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":8,"footnotes":""},"categories":[7],"tags":[],"class_list":["post-3285","post","type-post","status-publish","format-standard","hentry","category-grails"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Manoj Mohan\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Simple Client Side Ajax Validation | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Simple Client Side Ajax Validation | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly.\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#article\",\"name\":\"Simple Client Side Ajax Validation | TO THE NEW Blog\",\"headline\":\"Simple Client Side Ajax Validation\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/manoj\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2011-03-14T01:58:36+05:30\",\"dateModified\":\"2011-03-14T02:26:08+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#webpage\"},\"articleSection\":\"Grails\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#listItem\",\"name\":\"Simple Client Side Ajax Validation\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#listItem\",\"position\":3,\"name\":\"Simple Client Side Ajax Validation\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/manoj\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/manoj\\\/\",\"name\":\"Manoj Mohan\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51f6b8d1b9220effcec311fe0a79e0b5690c55d009ae52e10ccc2bebfab4273a?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Manoj Mohan\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/\",\"name\":\"Simple Client Side Ajax Validation | TO THE NEW Blog\",\"description\":\"Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/simple-client-side-ajax-validation\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/manoj\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/manoj\\\/#author\"},\"datePublished\":\"2011-03-14T01:58:36+05:30\",\"dateModified\":\"2011-03-14T02:26:08+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Simple Client Side Ajax Validation | TO THE NEW Blog","description":"Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly.","canonical_url":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#article","name":"Simple Client Side Ajax Validation | TO THE NEW Blog","headline":"Simple Client Side Ajax Validation","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/manoj\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2011-03-14T01:58:36+05:30","dateModified":"2011-03-14T02:26:08+05:30","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#webpage"},"articleSection":"Grails"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/www.tothenew.com\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#listItem","name":"Simple Client Side Ajax Validation"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#listItem","position":3,"name":"Simple Client Side Ajax Validation","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/manoj\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/manoj\/","name":"Manoj Mohan","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/51f6b8d1b9220effcec311fe0a79e0b5690c55d009ae52e10ccc2bebfab4273a?s=96&d=mm&r=g","width":96,"height":96,"caption":"Manoj Mohan"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/","name":"Simple Client Side Ajax Validation | TO THE NEW Blog","description":"Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/manoj\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/manoj\/#author"},"datePublished":"2011-03-14T01:58:36+05:30","dateModified":"2011-03-14T02:26:08+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Simple Client Side Ajax Validation | TO THE NEW Blog","og:description":"Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly.","og:url":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Simple Client Side Ajax Validation | TO THE NEW Blog","twitter:description":"Well my second month into work and I have started discovering things that are very trivial, but can save you a whole lot of time .. if you could get to know them better . One of those things was with jQuery. Now working with a normal submit form, a jQuery Validate Plugin works superbly.","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"3285","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 21:37:18","updated":"2024-02-29 09:32:21","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tSimple Client Side Ajax Validation\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Grails","link":"https:\/\/www.tothenew.com\/blog\/category\/grails\/"},{"label":"Simple Client Side Ajax Validation","link":"https:\/\/www.tothenew.com\/blog\/simple-client-side-ajax-validation\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=3285"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3285\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=3285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=3285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=3285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}