events - How to get a Boolean return value from jQuery trigger method? -


i have custom event want fire using jquery's trigger method:

$(wizard).trigger('validatingstepvalues'); 

then in wizard's current step code, subscribe event follow:

$(wizard).bind('validatingstepvalues', function (){     // validating step's form data here; returning false on invalid state. }); 

then in wizard, again want able stop user going next step, if false value returned validation process? i'd have like:

$(wizard).trigger('validatingstepvalues', validreturncallback, invalidreturncallback) 

have considered using like:

function wizardvalidator(successcallback, failurecallback) {     return function() {          // validating step's form data here;          if (wasvalid && successcallback) {             successcallback();         }          else if (! wasvalid && failurecallback) {             failurecallback();         }          return wasvalid;     }; }  $(wizard).bind('validatingstepvalues', wizardvalidator(validreturncallback, invalidreturncallback)); 

this requires know callbacks want use @ time bind event listener. if want able use different callback functions @ different times, define additional event types, like:

$(wizard).bind('validatingstep2values', wizardvalidator(validstep2returncallback, invalidstep2returncallback)); $(wizard).bind('validatingstep3values', wizardvalidator(validstep3returncallback, invalidstep3returncallback)); 

alternately, events create calling trigger() propagate dom hierarchy. returning false event handler cancels propagation. bind desired success callback function event listener on wizard's parent node. won't allow failure callback executed, however.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -