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
10 changes: 1 addition & 9 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@
"frm_admin_js": "readonly",
"ajaxurl": "readonly"
},
"overrides": [
{
"files": ["tests/js/*.test.mjs"],
"rules": {
"import/no-nodejs-modules": "off"
}
}
],
"rules": {
// Turn off rules that conflict with your codebase patterns.
"no-unused-vars": "off",
Expand Down Expand Up @@ -192,7 +184,7 @@
"rules": {
"import/no-nodejs-modules": [
"error",
{ "allow": ["node:test", "node:assert/strict"] }
{ "allow": ["node:test", "node:assert/strict", "node:fs", "node:vm", "node:module"] }
]
}
}
Expand Down
1 change: 1 addition & 0 deletions css/_single_theme.css.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

$settings = FrmStylesHelper::get_settings_for_output( $style );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable $style might not be defined


A variable has been used but not defined, which may result in warnings during program execution. This can also cause bugs since the intended usage scope of the variable is not known.

extract( $settings ); // phpcs:ignore WordPress.PHP.DontExtract
$style_class = $settings['style_class'];

$is_loaded_via_ajax = $is_loaded_via_ajax ?? false;
FrmStylesPreviewHelper::get_additional_preview_style( $settings, $is_loaded_via_ajax );
Expand Down
19 changes: 19 additions & 0 deletions css/custom_theme.css.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,25 @@
gap: 2%;
}

.with_frm_style.frm_inline_top .frm_submit.frm_flex,
.with_frm_style .frm_submit.frm_flex.frm_inline_submit {
align-items: flex-start;
align-content: flex-start;
row-gap: 0;
}

.with_frm_style.frm_inline_top .frm_submit.frm_flex::before,
.with_frm_style .frm_submit.frm_flex.frm_inline_submit::before {
flex-basis: 100%;
order: -2;
}

/* formidable.js sets the offset when a theme restyles the labels and the spacer no longer matches them. It must outrank the margin in each style's spacer rule. */
.frm_forms.with_frm_style.frm_inline_top .frm_fields_container .frm_submit::before,
.frm_forms.with_frm_style .frm_fields_container .frm_submit.frm_inline_submit::before {
margin-bottom: var(--frm-inline-submit-offset, 0);
}

<?php if ( $pro_is_installed ) { ?>
.with_frm_style .frm_submit.frm_flex button.frm_button_submit ~ .frm_prev_page {
order: -1;
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export default [
},
},
{
files: [ 'tests/js/style-live-preview.test.mjs', 'tests/js/paypalBootstrap.test.mjs' ],
files: [ 'tests/js/style-live-preview.test.mjs', 'tests/js/paypalBootstrap.test.mjs', 'tests/js/inlineSubmitAlignment.test.mjs' ],
rules: {
// The harnesses execute only checked-in scripts.
'sonarjs/code-eval': 'off',
Expand Down
124 changes: 124 additions & 0 deletions js/formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,129 @@ function frmFrontFormJS() {
}
}

/**
* Line up inline submit buttons with the inputs in the same row, then keep them lined up.
*
* @since x.x
*
* @return {void}
*/
function initInlineSubmitAlignment() {
let frameRequested = false;
const scheduleAlignment = function() {
if ( frameRequested ) {
return;
}
frameRequested = true;
window.requestAnimationFrame( function() {
frameRequested = false;
alignInlineSubmitButtons();
} );
};

alignInlineSubmitButtons();
window.addEventListener( 'load', scheduleAlignment );
window.addEventListener( 'resize', scheduleAlignment );
// Observe field sizes as well as the viewport, including forms revealed in popups.
const observed = new Set();
const resizeObserver = new ResizeObserver( scheduleAlignment );
const observeFields = () => {
for ( const element of observed ) {
if ( ! element.isConnected ) {
resizeObserver.unobserve( element );
observed.delete( element );
}
}
document.querySelectorAll( '.frm_inline_form .frm_fields_container > *' ).forEach( element => {
if ( ! observed.has( element ) ) {
observed.add( element );
resizeObserver.observe( element );
}
} );
scheduleAlignment();
};

observeFields();
// AJAX validation and pagination replace nodes. Newly inserted forms need observers too.
const mutationObserver = new MutationObserver( observeFields );
mutationObserver.observe( document.body, { childList: true, subtree: true } );

if ( document.fonts?.ready ) {
document.fonts.ready.then( scheduleAlignment );
}
}

/**
* The ::before spacer above an inline submit button copies the label size from the form style.
* A theme that restyles labels (for example `label { line-height: 1 }`) makes the real label
* taller or shorter than the spacer, so measure the difference and correct the spacer with it.
*
* @since x.x
*
* @return {void}
*/
function alignInlineSubmitButtons() {
document.querySelectorAll( '.with_frm_style.frm_inline_top .frm_fields_container > .frm_submit, .with_frm_style .frm_fields_container > .frm_submit.frm_inline_submit' ).forEach( alignInlineSubmitButton );
}

/**
* @since x.x
*
* @param {HTMLElement} submitContainer The .frm_submit element.
* @return {void}
*/
function alignInlineSubmitButton( submitContainer ) {
submitContainer.style.removeProperty( '--frm-inline-submit-offset' );

const input = getInlineSubmitRowInput( submitContainer );

if ( ! input ) {
return;
}

// Previous and Submit can wrap onto two rows in a narrow cell, so line up the top row.
const buttonTops = Array.from( submitContainer.children )
.filter( child => child.matches( 'button, input[type="submit"], input[type="button"], .frm_prev_page' ) && child.getClientRects().length )
.map( child => child.getBoundingClientRect().top );

if ( ! buttonTops.length ) {
return;
}

const offset = Math.round( ( input.getBoundingClientRect().top - Math.min( ...buttonTops ) ) * 100 ) / 100;

if ( Math.abs( offset ) >= 0.5 ) {
submitContainer.style.setProperty( '--frm-inline-submit-offset', `${ offset }px` );
}
}

/**
* Get the input closest to the submit button when it sits in the same row as the button.
*
* @since x.x
*
* @param {HTMLElement} submitContainer The .frm_submit element.
* @return {HTMLElement|null} The input, or null when the closest field is on another row.
*/
function getInlineSubmitRowInput( submitContainer ) {
const submitTop = submitContainer.getBoundingClientRect().top;
let sibling = submitContainer.previousElementSibling;

while ( sibling ) {
if ( sibling.classList.contains( 'frm_form_field' ) && sibling.getClientRects().length ) {
const input = sibling.querySelector( 'input:not([type="hidden"]), select, textarea' );

if ( input && input.getClientRects().length ) {
// Fields wrap onto their own row on narrow screens, and then there is nothing to line up with.
return Math.abs( sibling.getBoundingClientRect().top - submitTop ) < 1 ? input : null;
}
}
sibling = sibling.previousElementSibling;
}

return null;
}

function maybeShowNewTabFallbackMessage() {
if ( ! window.frmShowNewTabFallback ) {
return;
Expand Down Expand Up @@ -2852,6 +2975,7 @@ function frmFrontFormJS() {
documentOn( 'click', '.frm_error_link', focusFieldFromErrorLink );

initFloatingLabels();
initInlineSubmitAlignment();
maybeShowNewTabFallbackMessage();

jQuery( document ).on( 'frmAfterAddRow', setCustomValidityMessage );
Expand Down
Loading
Loading