-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add gap control #427
Conversation
Commit #d931831 adds 2 new actions: 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 |
@stijnvanouplines |
Hi @girafffee can you please have a look again? |
This will fix #142 & #383