Files
notifications-admin/app/assets/javascripts/updateStatus.js
Chris Hill-Scott 3fdaa29f35 Fetch template length message as user types
This commit adds some Javascript that makes AJAX requests as the users
changes the content of their template.

It then takes the content returned by the backend and inserts it in the
page.
2021-01-07 17:11:43 +00:00

42 lines
752 B
JavaScript

(function(window) {
"use strict";
window.GOVUK.Modules.UpdateStatus = function() {
let getRenderer = $component => response => $component.html(
response.html
);
this.start = component => {
let id = 'update-status';
this.$component = $(component);
this.$textbox = $('#' + this.$component.data('target'));
this.$textbox
.on('input', this.update)
.trigger('input');
};
this.update = () => {
$.ajax(
this.$component.data('updates-url'),
{
'method': 'post',
'data': this.$textbox.parents('form').serialize()
}
).done(
getRenderer(this.$component)
).fail(
() => {}
);
};
};
})(window);