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.

79 changes: 79 additions & 0 deletions js/src/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7078,7 +7078,86 @@ window.frmAdminBuildJS = function() {
replaceWith = replaceWith.trim();
}

const hadFrmFirstClass = field.classList.contains( 'frm_first' );

field.className = field.className.replace( replace, replaceWith );

if ( ! hadFrmFirstClass && field.classList.contains( 'frm_first' ) ) {
maybeBreakFieldGroup( field );
}
}

/**
* Break a field out of its field group when the frm_first class gets added to it.
*
* frm_first starts a new row, so FrmFieldGridHelper opens a new field group for the field
* the next time the builder loads. This applies the same split right away instead of
* leaving the builder showing a row that the reloaded form will not match.
*
* Fields after the target field move into the new group as well, since the new row is
* where they end up on reload too.
*
* @since x.x
*
* @param {HTMLElement} field The field that just had the frm_first class added to it.
* @return {void}
*/
function maybeBreakFieldGroup( field ) {
const list = field.parentElement;

if ( ! list || 'UL' !== list.nodeName || list.classList.contains( 'start_divider' ) ) {
// A field only ever needs breaking out when it is in a field group list.
return;
}

const fieldGroup = list.parentElement;

if ( ! fieldGroup || ! isFieldGroup( fieldGroup ) ) {
return;
}

const fieldsInRow = getFieldsInRow( jQuery( list ) ).get();

if ( fieldsInRow.indexOf( field ) < 1 ) {
// The field already starts its row, so there is nothing to break out of.
return;
}

const newList = tag( 'ul', { className: 'frm_grid_container frm_sorting' } );
const newFieldGroup = tag( 'li', { className: 'frm_field_box', child: newList } );

fieldGroup.after( newFieldGroup );
newList.append( ...getFieldAndFollowingFields( field ) );

makeDroppable( newList );
makeDraggable( newFieldGroup, '.frm-move' );

updateFieldGroupControls( jQuery( list ), getFieldsInRow( jQuery( list ) ).length );
}

/**
* Get a field along with every field that follows it in the same list.
*
* The field group controls are shared between every group and get appended to whichever
* group is hovered, so only list items are included.
*
* @since x.x
*
* @param {HTMLElement} field The field to start from.
* @return {Array.<HTMLElement>} The field and the fields after it.
*/
function getFieldAndFollowingFields( field ) {
const fields = [];

let sibling = field;
while ( sibling ) {
if ( 'LI' === sibling.nodeName ) {
fields.push( sibling );
}
sibling = sibling.nextElementSibling;
}

return fields;
}

function maybeShowInlineModal( e ) {
Expand Down
Loading