- Issue created by @sir_squall
- Status changed to Postponed: needs info
8 months ago 11:33am 1 February 2024 - 🇷🇸Serbia majmunbog
This code is not present in the 2.0.x version of Belgrade.
Can you update the issue metadata with the version you are using?
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);
Postponed: needs info
1.0
Code
This code is not present in the 2.0.x version of Belgrade.
Can you update the issue metadata with the version you are using?