Skip to content

Commit

Permalink
Remove evil and add valid and invalid function options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Deas committed Jun 11, 2018
1 parent 9000416 commit 566c7ca
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion formValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ $(document).ready(function() {

func = func.replace('this', '"' + val + '"');

var resp = eval(func);
var resp = Function('"use strict";return(' + func + ')')();
if (resp === true) {
addSuccess(this);
} else {
Expand All @@ -188,6 +188,13 @@ $(document).ready(function() {
function addError(self, message) {
self.error = true;

// If fv-valid-func exists then run the JS method
if ($(self).attr('fv-invalid-func') != "undefined") {
var func = $(self).attr('fv-invalid-func');

Function('"use strict";return(' + func + ')')();
}

message = message || '';
var id = $(self).attr('data-fvid');
if(typeof id != "undefined") {
Expand All @@ -211,6 +218,13 @@ $(document).ready(function() {
*/
function addSuccess(self) {
if (!self.error | self.validations == 1) {
// If fv-valid-func exists then run the JS method
if ($(self).attr('fv-valid-func') != "undefined") {
var func = $(self).attr('fv-valid-func');

Function('"use strict";return(' + func + ')')();
}

$(self).removeClass('fv-error').addClass('fv-success');
if($(self).siblings('.fv-error-message').length > 0) {
var id = $(self).attr('data-fvid');
Expand Down

0 comments on commit 566c7ca

Please sign in to comment.