Class: TBGForm

Defined in: vendor/assets/javascripts/styleguide/plugins/tbg-forms.js.coffee

Overview

FORM CLASS DEFINITION

Examples:

How to use the class

formInstance = new TBGForm $('.my-element')
# Send form
formInstance.send()

How to use the class with jQuery

$('.my-element').send()

How to ensure plugin self initialises on element

<form data-forms="/endpoint"> ... </form>

Instance Method Summary

Constructor Details

- (void) constructor(element)

Construct a new TBGForm instance

Parameters:

  • element (Object) form we will attach the TBGForm to

Instance Method Details

- (void) send()

Send the form, calls sendRequest passing form data and url to post to

- (void) sendRequest(data, url)

Execute ajax post

Parameters:

  • data (String) serialized form data
  • url (String) URL to post form to

- (void) showErrors(errors)

Handle form post errors - called from sendRequest error callback.

Clear previous errors, add error classes to relevent fields and labels and add error message summary

Parameters:

  • errors (Object) errors object

- (void) showSuccess(data)

Handle form post success - called from sendRequest success callback.

Pass empty error object to showErrors; if Handlebars defined call _showSuccessTemplated with data object otherwise call _showSuccessPlain; trigger 'tbgform-success' event with form data; fade form if necessary

Parameters:

  • data (Object) response from ajax post

- (void) _showSuccessTemplated(data) (private)

Display compiled success template

Compile template from data-formsSuccessContent; display with data object

Parameters:

  • data (Object) data object from showSuccess

- (void) _showSuccessPlain() (private)

Display success with replaced content

Display data-formsSuccessContent HTML