PageSourceSearch

https://rapidwelding.com/js/add-minus.js

js rapidwelding.com collected 2026-10-04 07:36:07 UTC 5,699 bytes, 129 lines download raw bytes

1/* =====================================================================
2   CHANGELOG
3   2026-09-28 - Quote-price lock (Dave found this): the minus button's disabled state was only ever set when
4                ViewBasket.aspx rendered. Raising the quantity with the + button is pure client-side JS with no
5                round trip, so a line that started AT its quoted floor kept a native disabled minus button
6                forever (a disabled button fires no click at all) until "Modify Basket" was clicked - even after
7                being raised well above the floor. Added applyQtyFloor(), called after every +/- click: if the
8                button that was clicked carries a data-qtyfloor attribute (only ViewBasket's multi-line quoted
9                rows have one - everywhere else this is a no-op), it disables/enables the matching minus button
10                and shows/hides its data-qtynote note purely client-side, and refuses to go below the floor at
11                all (clamps to it) rather than letting the customer decrement past it and have the server silently
12                reset it on save. Untouched: every other use of .qtyplus/.qtyminus on the site (product cards etc.)
13                has no data-qtyfloor attribute, so applyQtyFloor does nothing for them.
14   ===================================================================== */
15jQuery(document).ready(function(){
16    // This button will increment the value
17    $('.qtyplus').click(function(e){
18        // Stop acting like a button
19        e.preventDefault();
20        // Get the field name
21        fieldName = $(this).attr('field');
22        // Get its current value
23        var currentVal = parseInt($('input[name='+fieldName+']').val());
24        // If is not undefined
25        if (!isNaN(currentVal)) {
26            // Increment
27            $('input[name='+fieldName+']').val(currentVal + 1);
28        } else {
29            // Otherwise put a 0 there
30            $('input[name='+fieldName+']').val(0);
31        }
32        applyQtyFloor(fieldName);
33    });
34    // This button will decrement the value till 0
35    $(".qtyminus").click(function(e) {
36        // Stop acting like a button
37        e.preventDefault();
38        // Get the field name
39        fieldName = $(this).attr('field');
40        // Get its current value
41        var currentVal = parseInt($('input[name='+fieldName+']').val());
42        // If it isn't undefined or its greater than 0
43        if (!isNaN(currentVal) && currentVal > 0) {
44            // Decrement one
45            $('input[name='+fieldName+']').val(currentVal - 1);
46        } else {
47            // Otherwise put a 0 there
48            $('input[name='+fieldName+']').val(0);
49        }
50        applyQtyFloor(fieldName);
51    });
52});
53
54// 2026-09-28 - shared by both the initial binding above and the post-UpdatePanel-postback binding below.
55// fieldName is the "field" attribute shared by a QTY box's +/- buttons (eg "QTY-008023--L1"). Looks at the
56// MINUS button for that field: if it has a data-qtyfloor attribute (only set by ViewBasket.aspx on a
57// quote-price-locked multi-line row), clamps the textbox to that floor, and disables the minus button /
58// hides its note above the floor, enables/shows them again once back down at the floor. No-op for every
59// other +/- pair on the site, which never carries data-qtyfloor.
60function applyQtyFloor(fieldName) {
61    var $minus = $('.qtyminus[field="' + fieldName + '"]');
62    if ($minus.length === 0 || typeof $minus.attr('data-qtyfloor') === 'undefined') {
63        return;
64    }
65    var floor = parseInt($minus.attr('data-qtyfloor'));
66    var $qty = $('input[name=' + fieldName + ']');
67    var currentVal = parseInt($qty.val());
68    if (isNaN(currentVal)) {
69        return;
70    }
71    if (currentVal <= floor) {
72        // clamp - never let the client show a value below what the server will allow
73        $qty.val(floor);
74        $minus.prop('disabled', true);
75    } else {
76        $minus.prop('disabled', false);
77    }
78    var noteId = $minus.attr('data-qtynote');
79    if (noteId) {
80        if (currentVal <= floor) {
81            $('#' + noteId).show();
82        } else {
83            $('#' + noteId).hide();
84        }
85    }
86}
87
88var parameter = Sys.WebForms.PageRequestManager.getInstance();
89
90parameter.add_endRequest(function () {
91    //jquery code again for working after postback
92    // This button will increment the value
93    $('.qtyplus').click(function (e) {
94        // Stop acting like a button
95        e.preventDefault();
96        // Get the field name
97        fieldName = $(this).attr('field');
98        // Get its current value
99        var currentVal = parseInt($('input[name=' + fieldName + ']').val());
100        // If is not undefined
101        if (!isNaN(currentVal)) {
102            // Increment
103            $('input[name=' + fieldName + ']').val(currentVal + 1);
104        } else {
105            // Otherwise put a 0 there
106            $('input[name=' + fieldName + ']').val(0);
107        }
108        applyQtyFloor(fieldName);
109    });
110    // This button will decrement the value till 0
111    $(".qtyminus").click(function (e) {
112        // Stop acting like a button
113        e.preventDefault();
114        // Get the field name
115        fieldName = $(this).attr('field');
116        // Get its current value
117        var currentVal = parseInt($('input[name=' + fieldName + ']').val());
118        // If it isn't undefined or its greater than 0
119        if (!isNaN(currentVal) && currentVal > 0) {
120            // Decrement one
121            $('input[name=' + fieldName + ']').val(currentVal - 1);
122        } else {
123            // Otherwise put a 0 there
124            $('input[name=' + fieldName + ']').val(0);
125        }
126        applyQtyFloor(fieldName);
127    });
128
129});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.