Created
October 5, 2016 16:45
-
-
Save anareyna/e5eb3bb9847884b8922503a8dfff37a4 to your computer and use it in GitHub Desktop.
app js demo parsley
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
var App; | |
App = (function() { | |
var catchDom, dom, events, functions, initialize, st, subscribeEvents; | |
dom = {}; | |
st = { | |
body: "body", | |
frmParsley: ".frm-parsley" | |
}; | |
catchDom = function() { | |
dom.body = $(st.body); | |
dom.frmParsley = $(st.frmParsley); | |
}; | |
subscribeEvents = function() { | |
}; | |
events = { | |
}; | |
functions = { | |
configValidator: function() { | |
var ParsleyConfig; | |
ParsleyConfig = { | |
errorClass: 'has-error', | |
successClass: 'has-success', | |
classHandler: function(ParsleyField) { | |
return ParsleyField.$element.parents('.form-group'); | |
}, | |
errorsWrapper: '<span class="text-danger">', | |
errorTemplate: '<div></div>' | |
}; | |
dom.frmParsley.parsley(ParsleyConfig); | |
}, | |
extraValidators: function() { | |
window.ParsleyValidator.addValidator('notequalto', (function(value, requirement) { | |
return value !== $(requirement).val(); | |
}), 32).addMessage('es', 'notequalto', 'Este valor no deberia ser igual'); | |
window.ParsleyValidator.addValidator('gt', (function(value, requirement) { | |
return parseFloat(value) > parseFloat($(requirement).val()); | |
}), 32).addMessage('es', 'gt', 'Este valor deberia ser mayor'); | |
window.ParsleyValidator.addValidator('ge', (function(value, requirement) { | |
return parseFloat(value) >= parseFloat($(requirement).val()); | |
}), 32).addMessage('es', 'ge', 'Este número debería ser mayor o igual que el precio de venta'); | |
window.ParsleyValidator.addValidator('lt', (function(value, requirement) { | |
return parseFloat(value) < parseFloat($(requirement).val()); | |
}), 32).addMessage('es', 'lt', 'Este valor deberia ser menor'); | |
window.ParsleyValidator.addValidator('le', (function(value, requirement) { | |
return parseFloat(value) <= parseFloat($(requirement).val()); | |
}), 32).addMessage('es', 'le', 'Este número debería ser menor o igual que el precio tachado'); | |
} | |
}; | |
initialize = function() { | |
catchDom(); | |
subscribeEvents(); | |
$(function() { | |
functions.configValidator(); | |
functions.extraValidators(); | |
}); | |
}; | |
return { | |
init: initialize | |
}; | |
})(); | |
App.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment