Created
March 1, 2022 16:06
-
-
Save mboynes/1ee94d5b9b212181a21b74cb725dc71e to your computer and use it in GitHub Desktop.
Limit POST data on fieldmanager repeating groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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