Custom Increment number not working

Created on 31 January 2024, 10 months ago
Updated 5 February 2024, 10 months ago

Hi,

the increment is always 1 and it's not taking into account step, max and min, it should also work with negative number, see update
File: assets/js/custom_form_elements.js:
/**
* @file
* Belgrade Theme JS.
*/
(function ($, Drupal) {

'use strict';

/**
* Close behaviour.
*/
Drupal.behaviors.quantityIncDec = {
attach: function (context) {
$(".number-btn").once().on("click", function() {

var $button = $(this);
var oldValue = parseFloat($button.parent().find("input").val());
var newVal;
var min = parseFloat($button.parent().find("input").attr('min'));
var step = parseFloat($button.parent().find("input").attr('step'));
var max = parseFloat($button.parent().find("input").attr('max'));
const precision = 1000;

if ($button.text() === "+") {
if (oldValue >= max) {
newVal = max;
}else{
newVal = (oldValue * precision + step * precision) / precision ;
}
} else {
if (oldValue <= min) {
newVal = min;
}else{
newVal = (oldValue * precision - step * precision) / precision;
}
}

$button.parent().find("input").val(newVal);
});
}
};

})(jQuery, Drupal);

🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇨🇭Switzerland sir_squall

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024