Skip to content

Commit 1d2ae45

Browse files
committed
Merge branch 'ACP2E-3392' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-11-14-2024
2 parents ee6072e + 7ffb3e8 commit 1d2ae45

File tree

3 files changed

+37
-4
lines changed
  • app/code/Magento
  • dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/lib/validation

3 files changed

+37
-4
lines changed

app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
4+
* Copyright 2016 Adobe
5+
* All rights reserved.
66
*/
77
-->
88
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
@@ -293,7 +293,7 @@
293293
<scopeLabel>[GLOBAL]</scopeLabel>
294294
<validation>
295295
<rule name="validate-number" xsi:type="boolean">true</rule>
296-
<rule name="validate-greater-than-zero" xsi:type="boolean">true</rule>
296+
<rule name="validate-nonempty-number-greater-than-zero" xsi:type="boolean">true</rule>
297297
</validation>
298298
<label translate="true">Maximum Qty Allowed in Shopping Cart</label>
299299
<dataScope>max_sale_qty</dataScope>

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5-
5+
/* eslint-disable no-useless-escape */
6+
// jscs:disable no-useless-escape
67
/**
78
* @api
89
*/
@@ -626,6 +627,13 @@ define([
626627
},
627628
$.mage.__('Please enter a number greater than 0, without comma in this field.')
628629
],
630+
'validate-nonempty-number-greater-than-zero': [
631+
function (value) {
632+
return !isNaN(utils.parseNumber(value))
633+
&& value > 0 && (/^\s*-?\d+([,.]\d+)*\s*%?\s*$/).test(value);
634+
},
635+
$.mage.__('Please enter a number greater than 0, without comma in this field.')
636+
],
629637
'validate-css-length': [
630638
function (value) {
631639
if (value !== '') {

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/lib/validation/rules.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,31 @@ define([
9494
expect(rules['validate-number'].handler(value)).toBe(false);
9595
});
9696
});
97+
describe('"validate-nonempty-number-greater-than-zero" method', function () {
98+
it('Check on empty value', function () {
99+
var value = '';
100+
101+
expect(rules['validate-nonempty-number-greater-than-zero'].handler(value)).toBe(false);
102+
});
103+
104+
it('Check on integer', function () {
105+
var value = '125';
106+
107+
expect(rules['validate-nonempty-number-greater-than-zero'].handler(value)).toBe(true);
108+
});
109+
110+
it('Check on zero', function () {
111+
var value = '0';
112+
113+
expect(rules['validate-nonempty-number-greater-than-zero'].handler(value)).toBe(false);
114+
});
115+
116+
it('Check on not a number', function () {
117+
var value = 'string';
118+
119+
expect(rules['validate-nonempty-number-greater-than-zero'].handler(value)).toBe(false);
120+
});
121+
});
97122
});
98123

99124
describe('validate-color', function () {

0 commit comments

Comments
 (0)