Skip to content

Instantly share code, notes, and snippets.

@mboynes
Created March 1, 2022 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mboynes/1ee94d5b9b212181a21b74cb725dc71e to your computer and use it in GitHub Desktop.
Save mboynes/1ee94d5b9b212181a21b74cb725dc71e to your computer and use it in GitHub Desktop.
Limit POST data on fieldmanager repeating groups
'use strict';
jQuery(function ($) {
var $form = $('form#post');
if ($form.length && $('.fm-modules-wrapper').length) {
$form.submit(function (e) {
var $modules = $('.fm-modules-wrapper .fm-modules:not(.fmjs-proto)');
if ($modules.length) {
// Remove all protos to start.
var potentialFields = $('.fm-modules-wrapper :input[name*="[proto]"]');
// Go through all modules and remove the hidden/unused fields.
$modules.each(function (i, el) {
var $module = $(el),
type = $('.fm-module_type select', $module).val();
if ($module.length && type) {
potentialFields = $.merge(potentialFields, $('> .fm-group-inner > .fm-wrapper[data-display-src="module_type"][data-display-value!="' + type + '"]', $module).find(':input'));
}
});
// Re-enable disabled fields.
if (potentialFields.length) {
var disabledFields = [];
potentialFields.each(function (i, el) {
var $field = $(el);
if (!$field.prop('disabled')) {
$field.prop('disabled', true);
disabledFields.push($field);
}
});
setTimeout(function () {
disabledFields.map(function ($field) {
$field.prop('disabled', false);
});
}, 1000);
}
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment