app/assets/javascripts/lato_view/build/Validator.js in lato_view-1.1.4 vs app/assets/javascripts/lato_view/build/Validator.js in lato_view-1.1.5
- old
+ new
@@ -6,11 +6,11 @@
* @params:
* value: value to test
* @return: boolean
*/
var _isEmail = function(value) {
- return !/[0-9\-\.\_a-z]+@[0-9\-\.a-z]+\.[a-z]+/.test(value) ? true : false;
+ return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value) ? true : false;
};
/*
* Check if an input in a form has a number as its value.
* @params:
@@ -46,32 +46,45 @@
* Check if a required input is empty or not.
* @params
* attribute: data-attribute of form-control
* @return: boolean
*/
- var isInputRequired = function(attribute) {
- if($('.form-control[' + attribute + ']').length) {
+ var isInputRequired = function(inputs) {
+ if (inputs !== null && inputs.length) {
var passed = false;
- var $requiredInputs = '';
+ var results = [];
+ $.each(inputs, function(i, el) {
+ var passed = false;
+ var $requiredInputs = '';
- var isTextarea = $('.form-control[' + attribute + ']').find('.textarea').length;
- var $allInputs = $('.form-control[' + attribute + ']').find('.input, .textarea');
- var $onlyInput = $('.form-control[' + attribute + ']').find('.input');
+ var isTextarea = $(el).find('.textarea').length;
+ var $allInputs = $(el).find('.input, .textarea');
+ var $onlyInput = $(el).find('.input');
- var errorMessage = $('.required-hidden-message').text();
+ var errorMessage = $('.required-hidden-message').text();
+ $requiredInputs = isTextarea ? $allInputs : $onlyInput;
- $requiredInputs = isTextarea ? $allInputs : $onlyInput;
+ $requiredInputs.each(function(i, el) {
+ if ($(this).val() === '') {
+ passed = false;
+ $(this).parent('.form-control').addClass('form-required');
+ $requiredInputs.next('.input-error-message').text(errorMessage);
+ } else {
+ $(this).parent('.form-control').removeClass('form-required');
+ $requiredInputs.next('.input-error-message').text();
+ }
+ });
- $requiredInputs.each(function() {
- if($(this).val() === '') {
+ results.push(passed);
+ });
+
+ $.each(results, function(i, val) {
+ if (!val) {
passed = false;
- $(this).parent('.form-control').addClass('form-required');
- $requiredInputs.next('.input-error-message').text(errorMessage);
+ return false
} else {
passed = true;
- $(this).parent('.form-control').removeClass('form-required');
- $requiredInputs.next('.input-error-message').text();
}
});
return passed;
}
@@ -112,60 +125,69 @@
* Check if the value given is a correct email string
* @params
* input: input to control
* @return: undefined
*/
- var isInputEmail = function(input) {
- if ($(input).length) {
+ var isInputEmail = function(inputs) {
+
+ if (inputs !== null && inputs.length) {
var passed = false;
var results = [];
- var isSuggestion = $(input).parent('.eac-input-wrap').length;
- var $suggestionControl = $(input).parent('.eac-input-wrap').parent('.form-control');
- var $baseControl = $(input).parent('.form-control');
+ $.each($(inputs), function(i, el) {
+ var isSuggestion = $(el).parent('.eac-input-wrap').length;
+ var $suggestionControl = $(el).parent('.eac-input-wrap').parent('.form-control');
+ var $baseControl = $(el).parent('.form-control');
- // Distinguish when we have email suggestion or not
- var $formControl = isSuggestion ? $suggestionControl : $baseControl;
+ // Distinguish when we have email suggestion or not
+ var $formControl = isSuggestion ? $suggestionControl : $baseControl;
+ var errorMessage = $('.email-hidden-message').text();
- var errorMessage = $('.email-hidden-message').text();
+ var value = $(el).val();
- $(input).each(function () {
- var $value = $(this).val();
- passed = _isEmail($value) && !Util.isEmptyString($value);
- results[results.length] = passed;
- });
+ if (_isEmail(value) && !Util.isEmptyString(value)) {
+ passed = true;
- passed = results.indexOf(false);
+ $formControl.removeClass('form-error');
- if(passed === -1) {
-
- $formControl.addClass('form-error');
-
- // Distinguish when we have email suggestion or not
- if ($(input).parent('.eac-input-wrap').length) {
- $(input).parent('.eac-input-wrap').next('.input-error-message').text(errorMessage);
+ // Distinguish when we have email suggestion or not
+ if ($(el).parent('.eac-input-wrap').length) {
+ $(el).parent('.eac-input-wrap').next('.input-error-message').text('');
+ } else {
+ $(el).next('.input-error-message').text('');
+ }
} else {
- $(input).next('.input-error-message').text(errorMessage);
+ passed = false;
+ $formControl.addClass('form-error');
+
+ // Distinguish when we have email suggestion or not
+ if ($(el).parent('.eac-input-wrap').length) {
+ $(el).parent('.eac-input-wrap').next('.input-error-message').text(errorMessage);
+ } else {
+ $(el).next('.input-error-message').text(errorMessage);
+ }
}
-
- } else {
- $formControl.removeClass('form-error');
+ results.push(passed);
+ });
- // Distinguish when we have email suggestion or not
- if ($(input).parent('.eac-input-wrap').length) {
- $(input).parent('.eac-input-wrap').next('.input-error-message').text('');
+ console.log(results);
+
+ $.each(results, function(i, val) {
+ if (!val) {
+ passed = false;
+ return false
} else {
- $(input).next('.input-error-message').text('');
+ passed = true;
}
- }
+ });
return passed;
}
};
/*
* Check if two password inputs have the same value.
- * @params:
+ * @params:
* firstInput: first input to test
* secondInput: second input to test
* @return: boolean
*/
var isPasswordEqual = function(firstInput, secondInput) {