mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 02:42:26 -05:00
As part of https://github.com/alphagov/notifications-admin/pull/187 the file upload pattern was changed to auto-submit once a file had been picked. The form that was submitted was, however, missing a CSRF token, as well as a submit button for non-JS users. This commit makes the file upload pattern self-contained, so that it will always include a form with a CSRF token in a hidden input and a submit button, which is then hidden when Javascript loads.
22 lines
399 B
JavaScript
22 lines
399 B
JavaScript
(function(Modules) {
|
|
"use strict";
|
|
|
|
Modules.FileUpload = function() {
|
|
|
|
let $form;
|
|
|
|
this.submit = () => $form.trigger('submit');
|
|
|
|
this.start = function(component) {
|
|
|
|
$form = $(component);
|
|
|
|
// Need to put the event on the container, not the input for it to work properly
|
|
$form.on('change', '.file-upload-field', this.submit);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})(window.GOVUK.Modules);
|