Skip to content

Instantly share code, notes, and snippets.

@magevision
Created June 17, 2019 11:44
Show Gist options
  • Save magevision/988f46f0df9bad3939e7b1976d19c3b4 to your computer and use it in GitHub Desktop.
Save magevision/988f46f0df9bad3939e7b1976d19c3b4 to your computer and use it in GitHub Desktop.
AddCustomValidationSystemConfigurationField
var config = {
config: {
mixins: {
'mage/validation': {
'MageVision_Blog48/js/system/config/validator-rules-mixin': true
}
}
}
};
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="magevision" translate="label" sortOrder="1000">
<label>MageVision Blog Posts</label>
</tab>
<section id="blog48" translate="label" type="text" sortOrder="1010" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Post 48</label>
<tab>magevision</tab>
<resource>MageVision_Blog48::blog48_configuration</resource>
<group id="post48" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General</label>
<field id="custom_validation" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Custom Validation Greater than 1</label>
<validate>validate-greater-than-one</validate>
</field>
</group>
</section>
</system>
</config>
define([
'jquery'
], function ($) {
'use strict';
return function (target) {
$.validator.addMethod(
'validate-greater-than-one',
function (value) {
return !(value <= 1);
},
$.mage.__('Please enter a number 2 or greater in this field.')
);
return target;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment