saveFieldElements (JS API v2)

Version 2 API only.

saveFieldElements

Method Signature

void ultraCart.fire(callback);

Description

uses the map to transfer all the field values to the cart, calls updateCart async, and then runs the callback handler, if provided. This will allow the web page to chain the async update with another function - probably a handoff call.

Parameter

callback - optional callback function to execute after elements are saved. This is often a function that finalizes a check (see example)

Result

no return value



    // save all the field elements one last time
    ultraCart.saveFieldElements(function () {
      // when the save finishes, initiate the checkout.  do it asynchronously
      ultraCart.checkout(checkoutMethod || ultraCart.checkouts.CHECKOUT_ULTRACART, {async:true, onComplete:function(result) {
        // if the post is accepted, redirectToUrl will be populated.  This doesn't mean everything was successfully,
        // only that basic validation passed.  If there's any error, then the 'please wait' page will redirect back to this page
        // and the error parameter will be displayed.  By using ultraCart.checkout(), the default error parameter name of 'ucError' is used.
        // see handleCheckoutErrors()
        if (result.redirectToUrl) {
          ultraCart.util.postGet(result.redirectToUrl); // post instead of redirect to discourage back button use.

          // if the validation failed, then show errors and reset the finalize button.
        } else if (result.errors) {
          finalizing = false;
          jQuery('#finalizeLink').html("<img src='images/finalizeOrder.gif' alt='Finalize Order'/>");
          renderErrors(result.errors);

          // ?? this else block should never execute.
        } else {
          finalizing = false;
        }
      }})
    });