Created
August 24, 2017 13:10
-
-
Save naydav/87788dac8568ca9305fd72f3b2d1928e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Namespace/Module/view/adminhtml/requirejs-config.js | |
-- | |
var config = { | |
config: { | |
mixins: { | |
'mage/validation': { | |
'Namespace_Module/js/form/validation/validate-greater-than-field-value': true | |
} | |
} | |
} | |
}; | |
Namespace/Module/view/adminhtml/web/js/form/validation/validate-greater-than-field-value.js | |
-- | |
define([ | |
'jquery', | |
'Magento_Ui/js/lib/validation/validator', | |
'uiRegistry' | |
], function ($, validator, uiRegistry) { | |
'use strict'; | |
return function (target) { | |
validator.addRule( | |
'validate-greater-than-field-value', | |
function (value, params) { | |
var valueToCompare = uiRegistry.get(params.field).value(); | |
if ($.isNumeric(value) && $.isNumeric(valueToCompare)) { | |
return parseFloat(value) > parseFloat(valueToCompare); | |
} | |
return true; | |
} | |
); | |
return target; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment