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 css/frm_admin.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/formidable_admin.js

Large diffs are not rendered by default.

40 changes: 32 additions & 8 deletions js/src/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@

/*global jQuery:false, frm_admin_js, frmGlobal, ajaxurl, fromDom */

const MAX_FIELD_GROUP_SIZE = 12;

const frmAdminJs = frm_admin_js; // eslint-disable-line camelcase
const { tag, div, span, a, svg, img } = frmDom;
const { onClickPreventDefault } = frmDom.util;
Expand Down Expand Up @@ -457,7 +459,7 @@
return 'INPUT' === element.nodeName && 'checkbox' === element.type && ! element.checked;
}

/**

Check warning on line 462 in js/src/admin/admin.js

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected JSDoc block lines to be aligned
* Load a tooltip for a single element.
*
* @since x.x
Expand Down Expand Up @@ -2054,14 +2056,14 @@

function groupCanFitAnotherField( fieldsInRow, $field ) {
let fieldId;
if ( fieldsInRow.length < 6 ) {
if ( fieldsInRow.length < MAX_FIELD_GROUP_SIZE ) {
return true;
}
if ( fieldsInRow.length > 6 ) {
if ( fieldsInRow.length > MAX_FIELD_GROUP_SIZE ) {
return false;
}
fieldId = $field.attr( 'data-fid' );
// allow 6 if we're not changing field groups.
// Allow the maximum number if we're not changing field groups.
return 1 === jQuery( fieldsInRow ).filter( '[data-fid="' + fieldId + '"]' ).length;
}

Expand Down Expand Up @@ -2304,7 +2306,7 @@

function duplicateField() {
let $field, fieldId, children, newRowId, fieldOrder;
const maxFieldsInGroup = 6;
const maxFieldsInGroup = MAX_FIELD_GROUP_SIZE;

$field = jQuery( this ).closest( 'li.form-field' );
newRowId = this.getAttribute( 'frm-target-row-id' );
Expand Down Expand Up @@ -4118,7 +4120,10 @@
popup.appendChild( wrapper );
popup.appendChild( separator() );

popup.appendChild( getCustomLayoutOption() );
if ( sizeOfFieldGroup <= 6 ) {
popup.appendChild( getCustomLayoutOption() );
}

popup.appendChild( getBreakIntoDifferentRowsOption() );

return popup;
Expand Down Expand Up @@ -4184,6 +4189,12 @@
let wrapper, padding;

wrapper = getEmptyGridContainer();

if ( size > 6 ) {
wrapper.appendChild( getRowLayoutOption( size, 'even' ) );
return wrapper;
}

if ( 5 !== size ) {
wrapper.appendChild( getRowLayoutOption( size, 'even' ) );
}
Expand Down Expand Up @@ -4218,7 +4229,12 @@
useClass = 'frm_third';
break;
default:
useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third';
if ( size > 6 ) {
// We only show a single option at 6-12, so we use the full width.
useClass = 'frm_full';
} else {
useClass = size % 2 === 1 ? 'frm_fourth' : 'frm_third';
}
break;
}

Expand Down Expand Up @@ -4266,7 +4282,7 @@
}

/**
* @param {number} size 2-6.
* @param {number} size 2-12.
* @param {string} type even, middle, left, or right.
* @param {number} index 0-5.
* @return {string} The class name.
Expand All @@ -4289,7 +4305,15 @@
return 'frm12';
}

/**
* @param {number} size 2-12.
* @param {number|undefined} index 0-5.
* @return {string} The class name.
*/
function getEvenClassForSize( size, index ) {
if ( size > 6 ) {
return 'frm1';
}
if ( -1 !== [ 2, 3, 4, 6 ].indexOf( size ) ) {
return getLayoutClassForSize( 12 / size );
}
Expand Down Expand Up @@ -4924,7 +4948,7 @@
return false;
}
totalFieldCount += getFieldsInRow( jQuery( fieldGroup ) ).length;
if ( totalFieldCount > 6 ) {
if ( totalFieldCount > MAX_FIELD_GROUP_SIZE ) {
return false;
}
}
Expand Down
5 changes: 5 additions & 0 deletions resources/scss/admin/components/form/_form-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ form .frm_primary_label input {
#frm_form_editor_container .divider_section_only .frm_primary_label .frm-sub-label {
padding: 0;
}

// Hide the field ID when the field group has over 6 fields.
#frm-show-fields ul:has(> li:nth-child(7)) .frm-sub-label.frm-field-id {
display: none;
}
Loading