49

Check updates to the GitHub today, Magento 2 introduced new command to automatically generate all the URN resolutions for the PhpStorm. To use it: have Magento installed on the same machine as PhpStorm go to the root directory execute command bin/magento dev:urn-catalog:generate .idea/misc.xml where .idea/misc.xml is path to your PhpStorm misc.xml file ...


25

Excellent question! You don't need jQuery for this. You can do this with the built-in Magento form validator. First the javascript to set up the form for validation must be placed in your form template: <script type="text/javascript"> var myForm= new VarienForm('[your form id]', true); </script> Now prepare your form fields by adding the ...


24

Children of class Mage_Customer_Model_Customer should use getPasswordConfirmation() instead of getConfirmation() Upd: In class Mage_Customer_Model_Customer, method validate() was changed Before v1.9.1: $confirmation = $this->getConfirmation(); After: $confirmation = $this->getPasswordConfirmation(); https://github.com/speedupmate/Magento-CE-...


19

One thing you could try is to add a JavaScript mixin: In requirejs-config.js do: var config = { config: { mixins: { 'mage/validation': { 'Vendor_Module/js/validation-mixin': true } } } } and Vendor_Module/view/frontend/web/js/validation-mixin.js: define([ 'jquery' ], function ($) { "...


17

This is a configuration item. In Stores > Configuration > Customers > Customer Configuration > Password Options there's some options like Password Length and Number of Required Character Classes: Above I set the minimum password length to 20 and below I get the message when trying to create an account: Not sure at which version this was ...


17

You need to do add data-mage-init='{"validation":{}}' inside form declaration as following: <form class="form contact" action="<?php /* @escapeNotVerified */ echo $block->getFormAction(); ?>" id="contact-form" method="post" data-hasrequired="<?php /* @escapeNotVerified */ echo __('* Required Fields') ?>" data-mage-init=...


17

Just go-to that input field and add a custom attribute "data-msg-required" data-msg-(validator name) Like.. <input name="qty" id="qty" class="input-text" type="text" data-validate='{"required":true}' data-msg-required="Please select size."/>


15

Yes, use 127.0.0.1 instead of localhost. UPDATE `core_config_data` SET `value` = 'http://127.0.0.1/magento/' WHERE `core_config_data`.`path` = 'web/unsecure/base_url'; UPDATE `core_config_data` SET `value` = 'http://127.0.0.1/magento/' WHERE `core_config_data`.`path` = 'web/secure/base_url';


12

Your code is totally right. Both minimum and maximum need to be set with minimum-length-[0-9]+$ and maximum-length-[0-9]+$ What you are missing is to update the data-validate attribute by replacing: {required:true} With: {required:true, 'validate-length':true} Also you'll have to ensure that your custom form is validated via JavaScript with one of the ...


11

By Default Magento give number of validation classes.you just need to use the class name.Its easy find the html tag where their is mobile number html and add a class attribute to that input type and under the class add the following classes "validate-length maximum-length-10 minimum-length-10 validate-digits" Like in my case it was <input type="text" ...


10

So magento changed the XSD URI to use Urns - These need to be configured in PHP Storm in order for schema validation to work again. Source : http://alankent.me/2015/10/07/xml-schema-resolution-in-php-storm-with-urns-quick-note/ The URN resolution code is built into Magento directly. Luckily, it’s pretty easy to associate URNs with real files in your local ...


10

Magento is manage input fields validation using Html class and UI component. From checkout_index_index.xml layout file, magento is manage checkout shipping address fields validation,here magento define class for your input fields. So if we change class at here then it will working. For example telephone field, If you want to add validation of numeric. ...


10

I found my problem... Magento 2 has a built in feature that allows the user to specify countries for optional post code. In that feature, you can remove validation for selected countries. Settings can be found in: Admin Panel > Stores > Settings > Configuration > General > General > Country options > Zip/Postal Code is Optional for You have to un-tick ...


9

You can validate specific field using below code of line. <script> require([ 'jquery', 'mage/mage', ], function($){ $( "#new-button" ).click(function() { $('input[name="field_mobile"]').validation(); if(!$('input[name="field_mobile"]').validation('isValid')){ return false; } }); }); </script> ...


8

I was searching for an answer to that problem myself and I've merged both your answers as you have to do all these steps – so I'm undigging dead topic for future users. 1. First it's nice to run a SQL Query (i.e. in phpMyAdmin): UPDATE eav_attribute SET is_required = 0 WHERE attribute_code = 'lastname' 2. Get rid of classes for JS validation class="...


8

Try using Magento's validator's validate-date-range class on your fields. If you add this to both fields then it will get the to date and compare the two values. If get the to date value using the following code: var m = /\bdate-range-(\w+)-(\w+)\b/.exec(elm.className); if (!m || m[2] == 'to' || Validation.get('IsEmpty').test(v)) { return true; } So ...


8

It should be urn:magento:module:<Vendor_Module>:<path> The command will work since it filters out urns that begin with urn:magento https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Developer/Console/Command/XmlCatalogGenerateCommand.php#L118


8

To validate number you can use validate-number in your module checkout_index_index.xml file. Like :: <item name="telephone" xsi:type="array"> <item name="config" xsi:type="array"> <item name="tooltip" xsi:type="array"> <item name="description" xsi:type="string" translate="true">For delivery questions</item> ...


8

After so much investigation and implementation, I found a solution to display custom error message on checkout page. 1) Override a shipping.js file (vendor\magento\module-checkout\view\frontend\web\js\view\shipping.js) into your custom theme (app\design\frontend\Vendor\Theme\Module_Checkout\web\js\view\shipping.js): 2) Add your ajax call into ...


8

You Can do it by Script and update validation within it.You have to change 'validate_rules' => '{"max_text_length":255,"min_text_length":5}', You can change it directly from DB you have to do it carefully. Open table eav_attribute and find attribute_code street and get attribute_id from it (generally attribute_id is 28). Open table ...


7

"I always have admin login problems" is a bit vague but here goes Under System > Configuration > Web the settings should be as follows Also set "Session Lifetime (seconds)" under System > Configuration > Admin to a high value like 7200 so you don't need to login repeatedly


7

We can use jQuery validation in Magento 2. You can add this file in '.phtml' or '.js' file. Let’s see how we can do this. 1) In input or select tag add our validation with this code: data-validate="{required:true, 'validate-custom-pass':true}" 2) Add js validation for Validate-custom-pass validation script <script type="text/javascript"> require([...


7

add remote property for 'data-validate' attribute. example: <input name="email" id="email" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" value="" class="input-text" type="email" data-validate="{required:true, 'validate-email':true, 'remote':'<?php /* @escapeNotVerified */ echo $block->getValidateEmailAction(); ?>'}"/> Here $block->...


7

As @Wojtek Naruniec writes, you have to create your own custom validation method in a javascript file and use it in your module configuration field in system.xml file. Suppose your field as: <field id="color" translate="label comment" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Color</label> ...


6

The customer attributes has no is_unique option which is available for product attributes. The uniqueness of email is verified programatically in \Mage_Customer_Model_Resource_Customer::_beforeSave. So you can just mimic it for your attribute.


6

Schema is for validation of merged configuration (configuration taken from xml files of all modules) Per file schema is for validation of separate xml files. The reason for this separation is that there are situations when constraints for each separate file are softer than for merged configuration. This might happen because merged configuration should be ...


6

Assuming you add a validation class via the frontend_class let's say "validate-custom-class" you'll need to use the following JS to add a custom validation based on a this class: require([ 'jquery', 'jquery/ui', 'jquery/validate', 'mage/translate' ], function($){ $.validator.addMethod( 'validate-custom-class', function (value) { ...


6

Firstly, Magento's validation for checkout_index_index.xml is not working properly so, you have to insert the rules while you replace the street fields. You can do this by creating a plugin and insert the fields in Layout AfterProcessor. `namespace/module/etc/frontend/di.xml` ... <type name="Magento\Checkout\Block\Checkout\LayoutProcessor"> ...


6

We should create new validation classes: validate-filesize, validate-fileextensions & validate-image-height-width. require([ 'jquery', 'jquery/ui', 'jquery/validate', 'mage/translate' ], function ($) { //Validate Image FileSize $.validator.addMethod( 'validate-filesize', function (v, elm) {...


6

Hi @Jurģis Toms Liepiņš - your answer helped me a lot! It appears there are two JavaScript validation implementations: mage/validation.js The mage/validation file is referenced by mage/validation/validation, which is mapped with RequireJS to validation. Inchoo has an article on how to use this. Magento_Ui/js/lib/validation/rules.js The Magento_Ui/...


Only top voted, non community-wiki answers of a minimum length are eligible