Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/formidable_admin.js

Large diffs are not rendered by default.

31 changes: 27 additions & 4 deletions js/src/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3268,6 +3268,12 @@ window.frmAdminBuildJS = function() {
return `field_options${ opt.substring( 0, at ) }_${ fieldId }${ opt.substring( at ) }`;
}

/**
* Populates the calculation field list.
*
* @param {HTMLElement} element The calculation box element.
* @param {boolean} force Whether to force the refresh.
*/
function popCalcFields( element, force ) {
const settingsBox = jQuery( element ).closest( '.frm-single-settings' );
const calc = settingsBox.find( '.frm-calc-field' );
Expand All @@ -3287,10 +3293,21 @@ window.frmAdminBuildJS = function() {
box = document.getElementById( `frm-calc-box-${ fieldId }` );
}

const exclude = getExcludeArray( box, isSummary );
const codeList = box.querySelector( '.frm_code_list' );
const exclude = getExcludeArray( codeList, isSummary );
const excludedOpts = extractExcludedOptions( exclude );

const fields = getFieldList();
/**
* Filters the fields offered in a calculation box.
*
* Add-ons that own a calculation type can drop fields it can't use. When
* nothing is hooked in, every field is offered, matching the behavior
* before calculation-type specific filtering existed.
*
* @param {Array} fields The candidate fields.
* @param {Object} args Context with the box, code list, and isSummary flag.
*/
const fields = wp.hooks.applyFilters( 'frm_calc_field_list', getFieldList(), { box, codeList, isSummary } );
const list = document.getElementById( `frm-calc-list-${ fieldId }` );
list.innerHTML = '';

Expand All @@ -3315,8 +3332,14 @@ window.frmAdminBuildJS = function() {
}
}

function getExcludeArray( calcBox, isSummary ) {
const codeList = calcBox.querySelector( '.frm_code_list' );
/**
* Gets the exclude array for the calculation box.
*
* @param {HTMLElement} codeList The code list element.
* @param {boolean} isSummary Whether the calculation box is for a summary.
* @return {Array} The exclude array.
*/
function getExcludeArray( codeList, isSummary ) {
const exclude = JSON.parse( codeList.getAttribute( 'data-exclude' ) );

if ( isSummary ) {
Expand Down
Loading