Last active
August 29, 2015 14:17
-
-
Save andersr/b1a222ce6bc048949712 to your computer and use it in GitHub Desktop.
Disable submit unless all required fields have values
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
# disable submit unless all fields with .require_field class have values | |
$(document).ready -> | |
total_required_fields = 0 | |
$( ".required_field" ).each -> | |
total_required_fields += 1 | |
if $(this).val().trim().length == 0 | |
$('[type="submit"]').attr("disabled", "disabled") | |
else | |
$('[type="submit"]').removeAttr("disabled", "disabled") | |
$(".required_field").keyup -> | |
filled_required_fields = 0 | |
$( ".required_field" ).each -> | |
if $(this).val().trim().length > 0 | |
filled_required_fields +=1 | |
if filled_required_fields == total_required_fields | |
$('[type="submit"]').removeAttr "disabled" | |
else | |
$('[type="submit"]').attr("disabled", "disabled") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment