Skip to content

Instantly share code, notes, and snippets.

@nkb-bd
Created October 4, 2023 17:38
Show Gist options
  • Save nkb-bd/2f75122d466fc26edf5b96da4860cd3e to your computer and use it in GitHub Desktop.
Save nkb-bd/2f75122d466fc26edf5b96da4860cd3e to your computer and use it in GitHub Desktop.
Fluent Forms : Number field with buttons
/*
* Fluent Form : Creating a Number field with + / - Button embeded with the input field
* Take a Numeric Field then add element class 'incremental-input', thats it
*/
add_filter('fluentform/rendering_field_data_input_number', function ($data) {
if ($data['attributes']['class'] == 'incremental-input') {
$data['settings']['prefix_label'] = '<button class="ff-btn-step-plus">+</button>';
$data['settings']['suffix_label'] = '<button class="ff-btn-step-minus">-</button>';
}
return $data;
});
add_action('wp_footer', function () {
?>
<script>
jQuery(document).ready(function ($) {
$('.ff-btn-step-plus, .ff-btn-step-minus').click(function (e) {
e.preventDefault();
const inputField = $(this).closest('.ff_input-group').find('input[type="number"]');
if (inputField.length) {
let currentValue = parseFloat(inputField.val()) || 0;
if ($(this).hasClass('ff-btn-step-plus')) {
currentValue += 1;
} else if ($(this).hasClass('ff-btn-step-minus')) {
currentValue -= 1;
}
inputField.val(currentValue);
}
});
});
</script>
<?php
});
@aimanmatripin
Copy link

This one work perfectly! . But if i use as quantity and put the payment summary module before the payment, unfortunately total amount is not updated if we change quantity using this button. Hope there will be new update on this little bug.

@dreamzspl
Copy link

Hello! Thanks for sharing this script. I have a really newbie question - may I know where should this script be uploaded to? Is it to the root Wordpress directory? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment