Created
October 18, 2011 01:42
-
-
Save tdouce/1294414 to your computer and use it in GitHub Desktop.
amware - refactor #6
This file contains hidden or 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
// When user clicks 'submit' button loop through all selects with a 'datetime' class. | |
// Find the select element that furtherest DOWN the DOM. | |
// Add a warning to any other select elememnt that has an empty value that | |
// is further UP the DOM | |
$(".commit").click( function(e){ | |
// Html warning to append. Create a unique class name ('javascript_warning') | |
// to faciliate identifying and removing ONLY the warnings thata are added with this function. | |
// NOTE: We are piggy-backing on the existing css for the errors by using the 'inline-errors' class. | |
var warning_html = '<p class="inline-errors javascript_warning"> Warning, this is blank </p>'; | |
// Remove any previous javascript warnings that we added with this function ONLY | |
$('.javascript_warning').remove(); | |
// Flag for identifying whether or not we should add a warning. | |
var post_warning = false; | |
// Get all the elements and reverse them so we can iterate backwards through the DOM | |
$($( '.datetime' ).get().reverse()).each( function(){ | |
// Find the select element that furtherest DOWN the DOM. Add a warning to any | |
// other select elememnt that has an empty value that is further UP the DOM | |
$(this).find('select').each(function(){ | |
// If select element has a value then change the flag to 'true' | |
if ( $(this).val() != "" ) | |
{ | |
post_warning = true; | |
} | |
// If select element is blank and the flag has already been set to | |
// 'true', then add a warning, stop form submission, and break out of | |
// loop so only one warning is added (rather than 5) | |
else if( $(this).val() == "" & post_warning == true ) | |
{ | |
$(this).closest('.datetime').append( warning_html ); | |
e.preventDefault(); | |
return false; | |
}; | |
}); | |
}); |
This file contains hidden or 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
// When user clicks 'submit' button loop through all selects with a 'datetime' class. | |
// Find the select element that furtherest DOWN the DOM. | |
// Add a warning to any other select elememnt that has an empty value that | |
// is further UP the DOM and stop the form submission. | |
$(".commit").click( function(e){ | |
// Html warning to append. Create a unique class name ('javascript_warning') | |
// to faciliate identifying and removing ONLY the warnings thata are added with this function. | |
// NOTE: We are piggy-backing on the existing css for the errors by using the 'inline-errors' class. | |
var warning_html = '<p class="inline-errors javascript_warning"> Warning, this is blank </p>'; | |
// Remove any previous javascript warnings that we added with this function ONLY | |
$('.javascript_warning').remove(); | |
// Flag for identifying whether or not we should add a warning. | |
var post_warning = false; | |
// Get all the elements and reverse them so we can iterate backwards through the DOM | |
$($( '.datetime' ).get().reverse()).each( function(){ | |
// Find the select element that furtherest DOWN the DOM. Add a warning to any | |
// other select elememnt that has an empty value that is further UP the DOM | |
$(this).find('select').each(function(){ | |
// If select element has a value then change the flag to 'true' | |
if ( $(this).val() != "" ) | |
{ | |
post_warning = true; | |
} | |
// If select element is blank and the flag has already been set to | |
// 'true', then add a warning, stop form submission, and break out of | |
// loop so only one warning is added (rather than 5) | |
else if( $(this).val() == "" & post_warning == true ) | |
{ | |
$(this).closest('.datetime').append( warning_html ); | |
e.preventDefault(); | |
return false; | |
}; | |
}); | |
}); |
Thanks, man. Coming from you, then it must be quality code. It only took
six iterations. So, the answer is...."Is it Highgroove worthy?". I hope
so;)
Love you,
T
On Tue, Oct 18, 2011 at 1:48 PM, Jonathan Wallace < ***@***.***>wrote:
NICE!
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1294414
##
Travis Douce
Assistant Information Manager/GIS Specialist
Department of Marine Sciences
University of Georgia
Athens, Georgia 30602-3636
Office Phone: (706) 542-5955
Fax: (706) 542 5888
[email protected]
[email protected]
I only went out for a walk, and finally concluded to stay out
until sundown, for going out, I found was really going in. - John Muir
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NICE!