/* The objct links to a TABLE (no form), perform error checking and executes specified function if no errors. The form INSTANTIATES: Insert, Update, Delete buttons, User Message Errors: checked on all fields, according to the button clicked. Upon error detection: builds the User Message, displays it and returns True/False in pCbkAfterCheck RELATIONAL ERRORS cannot be detected at this level. Verification should be performed at the UI level. CONVENTION ----------- - Insert: TD with id: idBtnInsert - Update: TD with id: idBtnUpdate - Delete: TD with id: idBtnDelete NOTE: Only one button of a type / form Button syntax ------------ IdBtn FIELDS ------ - Mandatory/optional fields are specieid in form through their classes Includes -------- */ $.fn.uaForm = function(options) { options = $.extend({ pItems : null //items in form subject for AJAX xfer }, options);//options this. on(EV_INIT,function(ev) { ev.stopImmediatePropagation(); $.each(options.pItems,function() { $(this).trigger(EV_INIT); }); }). on(EV_CLEAR,function(ev) { ev.stopImmediatePropagation(); $.each(options.pItems,function() { $(this).trigger(EV_CLEAR); }); }). on(EV_SET_DEFAULT,function(ev) { ev.stopImmediatePropagation(); $.each(options.pItems,function() { $(this).trigger(EV_SET_DEFAULT); }); }). on(EV_CHECK_FOR_ERRORS,function(ev) { ev.stopImmediatePropagation(); $.each(options.pItems,function() { $(this).trigger(EV_CHECK_FOR_ERRORS); }); }); this.hasErrors = function() { let bErrors= false; /* $.each(options.pItems,function() { bErrors |= $(this).hasClass('border-danger') || $(this).hasClass('text-danger'); return !bErrors; }); */ $.each(options.pItems,function() { switch(this.hasErrors) { case undefined: bErrors |= $(this).hasClass('border-danger'); break; default: bErrors |= this.hasErrors(); break; }; }); //return bErrors===1? true:false; return bErrors===1; }; this.clearErrors = function() { $.each(options.pItems,function() { $(this).trigger(EV_CLEAR_ERRORS); }); return this; }; return this; };//nkTdForm