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
- - (void) constructor(element) Constructor Construct a new TBGForm instance
- - (void) send() Send the form, calls sendRequest passing form data and url to post to
- - (void) sendRequest(data, url) Execute ajax post
- - (void) showErrors(errors) Handle form post errors - called from sendRequest error callback.
- - (void) showSuccess(data) Handle form post success - called from sendRequest success callback.
- - (void) _showSuccessTemplated(data) Private Display compiled success template Compile template from data-formsSuccessContent; display with data object
- - (void) _showSuccessPlain() Private Display success with replaced content Display data-formsSuccessContent HTML
Constructor Details
- (void) constructor(element)
Construct a new TBGForm instance
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
- (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
- (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
- (void) _showSuccessTemplated(data) (private)
Display compiled success template
Compile template from data-formsSuccessContent; display with data object
- (void) _showSuccessPlain() (private)
Display success with replaced content
Display data-formsSuccessContent HTML