Skip to content

Instantly share code, notes, and snippets.

@hmcq6
Last active March 1, 2017 15:34
Show Gist options
  • Save hmcq6/2da844a2a3868226480a0f561b0470c1 to your computer and use it in GitHub Desktop.
Save hmcq6/2da844a2a3868226480a0f561b0470c1 to your computer and use it in GitHub Desktop.
;
if (!FDE) {
let FDE = {};
}
FDE.Manufacturer = {
formSelector: '.manufacturer-form',
_handleErrors(_event, data, _error, _status) {
$.each(data.responseJSON, function(field, message) {
let $field = $('input#manufacturer_' + field);
FDE.Form.showError($field, message);
});
},
_handleSuccess(_event, data, _status, _xhr) {
window.location = data.link;
},
formSubmit() {
let $form = $(this.formSelector);
if($form.isValid()) {
$form.trigger('submit.rails');
$form.on('ajax:success', this._handleSuccess).
on('ajax:error', this._handleErrors);
}
}
};
$(function () {
$('.manufacturer-form .submit').on('click', FDE.Manufacturer.formSubmit.bind(FDE.Manufacturer));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment