I have a small jQuery plugin that I use to validate an AJAX form. There is a callback that warns of a script call of each "step" in the check / submit process.
Some snippets:
(function ($) {
$.fn.formHelper = function (options) {
var stage = { Start: 1, ErrorReceived: 2, AllErrorsReceived: 3, NoErrors: 4 };
};
})(jQuery);
$("#some_button").formHelper({
StageCallback: someCallbackHandler;
});
function someCallbackHandler(stage) {
switch(stage) {
case 1: alert("Starting validation"); break;
case 2: alert("Error received"); break;
case 3: alert("All errors received"); break;
case 4: alert("No errors"); break;
}
}
Question: How can I set the stage variable of my plugin so that I can use it like this (which is easier to read than to use numbers)?
function someCallbackHandler(stage) {
if (stage == $.formHelper.stage.Start)
alert("Starting validation");
}
I assume that the notation ".formHelper.stage.Start" is not accurate, but I hope that I expressed my point of view.
source
share