mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-24 18:09:13 -04:00
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.
This commit is contained in:
41
app/assets/javascripts/updateStatus.js
Normal file
41
app/assets/javascripts/updateStatus.js
Normal file
@@ -0,0 +1,41 @@
|
||||
(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);
|
||||
Reference in New Issue
Block a user