Last active
March 1, 2017 15:34
-
-
Save hmcq6/2da844a2a3868226480a0f561b0470c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
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