Created
October 31, 2011 08:49
-
-
Save kubido/a630cb8961351024cf15 to your computer and use it in GitHub Desktop.
add client validation for search form if it's input is null
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('form[action*="search"]').live('submit', function(event) { | |
event.preventDefault(); | |
arr_input = $('form').serializeArray(); | |
arr_input.shift(); | |
keywords_count = 0; | |
$.map(arr_input, function(el){ | |
if(el.value != ""){keywords_count = keywords_count + 1} | |
}); | |
if(keywords_count <= 0){ | |
if($('.error.empty-search').length < 1){ | |
error_el = '<div class="alert-message error empty-search" style="display:none" data-alert="alert"><a class="close" href="#">×</a>Enter at least one search term to perform any search</div>' | |
$('.breadcrumb').append(error_el) | |
$('.error.empty-search').fadeIn('slow'); | |
} | |
}else{ | |
$(this).attr({ | |
'data-pjax': '#content', | |
'data-pjax-fragment': '#content' | |
}); | |
$('form').submit() | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment