-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: form validation across all browsers
- Loading branch information
1 parent
74aa84e
commit d4ed0bd
Showing
9 changed files
with
160 additions
and
45 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
fieldValidation = (checkThis) -> | ||
isValid = true; | ||
$checkThis = $(checkThis) | ||
|
||
if $.trim($checkThis.val()).length | ||
$checkThis.removeClass('invalid') | ||
else | ||
isValid = false | ||
$checkThis.addClass('invalid') | ||
return isValid | ||
|
||
validation = -> | ||
$('form').submit -> | ||
isValid = true | ||
$inputs = $(this).find('[required]') | ||
$inputs.each -> | ||
$input = $(this) | ||
if !fieldValidation($input) | ||
isValid = false | ||
return true | ||
if !isValid | ||
return false | ||
|
||
$('form *').focusout -> | ||
fieldValidation(this) | ||
|
||
$('input[type="radio"]').on 'click', (e) -> | ||
if $('#compensation_no').is(':checked') | ||
$('#compensation_no').addClass('invalid') | ||
$('#compensation_alert').removeClass('hidden') | ||
$('#submit_form').attr('disabled','disabled') | ||
else | ||
$('#compensation_no').removeClass('invalid') | ||
$('#compensation_alert').addClass('hidden') | ||
$('#submit_form').removeAttr('disabled') |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var fieldValidation, validation; | ||
|
||
fieldValidation = function(checkThis) { | ||
var $checkThis, isValid; | ||
isValid = true; | ||
$checkThis = $(checkThis); | ||
if ($.trim($checkThis.val()).length) { | ||
$checkThis.removeClass('invalid'); | ||
} else { | ||
isValid = false; | ||
$checkThis.addClass('invalid'); | ||
} | ||
return isValid; | ||
}; | ||
|
||
validation = function() { | ||
$('form').submit(function() { | ||
var $inputs, isValid; | ||
isValid = true; | ||
$inputs = $(this).find('[required]'); | ||
$inputs.each(function() { | ||
var $input; | ||
$input = $(this); | ||
if (!fieldValidation($input)) { | ||
isValid = false; | ||
} | ||
return true; | ||
}); | ||
if (!isValid) { | ||
return false; | ||
} | ||
}); | ||
$('form *').focusout(function() { | ||
return fieldValidation(this); | ||
}); | ||
return $('input[type="radio"]').on('click', function(e) { | ||
if ($('#compensation_no').is(':checked')) { | ||
$('#compensation_no').addClass('invalid'); | ||
$('#compensation_alert').removeClass('hidden'); | ||
return $('#submit_form').attr('disabled', 'disabled'); | ||
} else { | ||
$('#compensation_no').removeClass('invalid'); | ||
$('#compensation_alert').addClass('hidden'); | ||
return $('#submit_form').removeAttr('disabled'); | ||
} | ||
}); | ||
}; |
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
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
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