Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gap control #427

Merged
merged 6 commits into from
May 21, 2024
Merged

Add gap control #427

merged 6 commits into from
May 21, 2024

Conversation

stijnvanouplines
Copy link
Contributor

@stijnvanouplines stijnvanouplines commented Apr 18, 2024

This will fix #142 & #383

@stijnvanouplines
Copy link
Contributor Author

Commit #d931831 adds 2 new actions: jet-form-builder/before-field & jet-form-builder/after-field

Now it’s possible to add elements before or after a field. For example you can add a minus and plus button to a number field:

add_action( 'jet-form-builder/before-field', function ($that) {
    if (isset($that->args['name']) && $that->args['name'] === 'quantity') {
        echo '<button type="button" class="minus">-</button>';
    }
} );
add_action( 'jet-form-builder/after-field', function ($that) {
    if (isset($that->args['name']) && $that->args['name'] === 'quantity') {
        echo '<button type="button" class="plus">+</button>';
    }
} );

Use this little code snipped to make the buttons work:

document.querySelectorAll( '.jet-form-builder__field-wrap:has([name="quantity"])' ).forEach( ( field ) => {
    field.addEventListener( 'click', ( event ) => {
        const input = field.querySelector( 'input' );
        const value = parseFloat( input.value );
        const min = parseFloat( input.getAttribute( 'min' ) );
        const max = parseFloat( input.getAttribute( 'max' ) );
        const step = parseFloat( input.getAttribute( 'step' ) );

        if ( event.target.classList.contains( 'plus' ) ) {
            if ( max && ( max <= value ) ) {
                input.value = max;
            } else {
                input.value = value + step;
            }
        } else {
            if ( min && ( min >= value ) ) {
                input.value = min;
            } else if ( value > min ) {
                input.value = value - step;
            }
        }
    });
});

The idea came from WooCommerce

@girafffee
Copy link
Contributor

@stijnvanouplines
Without looking at the details, in general, thank you for your contribution:)

@stijnvanouplines
Copy link
Contributor Author

Hi @girafffee can you please have a look again?

@girafffee girafffee merged commit 7c8a97d into Crocoblock:main May 21, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

version 2.1.2 replicates photo into media if you enter and edit post.
2 participants