Introduction


This namespace contains form submission functions that helps you control how the form will be submitted. And whereas to validate form before submission. In addition to some changes for submit button including:

  • It'll be disabled. This helpful to prevent submitting form several times continuously.
  • It'll show loading icon.

These changes last as long as the submission hasn't finished. Once finished, the button automatically restore it's original status.


Normal Submission



spa.form.submit(form, submitter, validate)


Normally submit the form.

Parameter Type Description
form string | JQuery The form as jQuery selector string or as JQuery object.
submitter string | JQuery Submit button as jQuery selector string or as JQuery object.
validate boolean Whereas to validate the form before submission or not. If the form is not valid, the submission is cancelled and the validation errors is shown according to selected validation driver.

spa.form.registerNormalSubmitter(form, submitter, validate)


Instead of using spa.form.submit(form, submitter, validate) with every form, you can register normal form submitter globally with single call to spa.form.registerNormalSubmitter(form, submitter, validate).

Parameter Type Description
form string | JQuery The form as jQuery selector string or as JQuery object.
submitter string | JQuery Submit button as jQuery selector string or as JQuery object.
validate boolean Whereas to validate the form before submission or not. If the form is not valid, the submission is cancelled and the validation errors is shown according to selected validation driver.

Ajax Submission



spa.form.submitAjax(form, submitter, validate, fn)


Submit form using ajax request. Note that this function returns the jqXHR object returned by $.ajax() which implements the Promise interface. This means that you still can use Promise methods of the jqXHR object. For example: done, fail or always.

Parameter Type Description
form string | JQuery The form as jQuery selector string or as JQuery object.
submitter string | JQuery Submit button as jQuery selector string or as JQuery object.
validate boolean Whereas to validate the form before submission or not. If the form is not valid, the submission is cancelled and the validation errors is shown according to selected validation driver.
fn function Function callback to call if the submission end successfully

spa.form.registerAjaxSubmitter(form, submitter, validate, fn)


Instead of using spa.form.submitAjax(form, submitter, validate, fn) with every form, you can register ajax form submitter globally with single call to spa.form.registerAjaxSubmitter(form, submitter, validate, fn).

Parameter Type Description
form string | JQuery The form as jQuery selector string or as JQuery object.
submitter string | JQuery Submit button as jQuery selector string or as JQuery object.
validate boolean Whereas to validate the form before submission or not. If the form is not valid, the submission is cancelled and the validation errors is shown according to selected validation driver.
fn function Function callback to call if the submission end successfully

Form Inputs As Object



spa.form.getFormInputsAsObject(form)


Get form inputs as object. Each form input is converted into attribute where the attribute name is the input name and the attribute value is the input value.

Parameter Type Description
form string | JQuery The form as jQuery selector string or as JQuery object.