Skip to content

Instantly share code, notes, and snippets.

@zaxbux
Last active January 25, 2020 04:32
Show Gist options
  • Save zaxbux/8478eeb8e4a11a2dc30f355842291f15 to your computer and use it in GitHub Desktop.
Save zaxbux/8478eeb8e4a11a2dc30f355842291f15 to your computer and use it in GitHub Desktop.
Modify request data before submit (October CMS Backend forms)
// Listen to AJAX setup event
// This event is fired before request is formed
// Allows the request data to override input values
// Useful for custom controls, input masks, etc
$(window).on('ajaxSetup', function (e, context) {
// Find the form and inputs from e.target (the submit button)
// Select specific forms and inputs by modifying $('form') and $('input')
$(e.target).closest('form').find('input').each(function() {
var inputName = $(this).attr('name'),
inputValue = $(this).val();
// Modify inputValue here
// ...
// Set the modified value
context.options.data[inputName] = inputValue;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment