Add Custom Validation Rule Magento 2 Validate.js Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Custom form validation using ajax.updater in magentoCombined form fields validationValidation not working on custom field at register.phtmlCustom checkboxes form Validation - MagentoHow to override Catalog Price Rules?Use cases for different JS init methodsHow to add custom js form validation with custom error message in magento2?Magento 2 add custom validation ruleMagento 2 Custom Validation RuleMagento 2.2.5: How to validate shipping address

Why are vacuum tubes still used in amateur radios?

What initially awakened the Balrog?

How to report t statistic from R

What does it mean that physics no longer uses mechanical models to describe phenomena?

Misunderstanding of Sylow theory

Did any compiler fully use 80-bit floating point?

Electrolysis of water: Which equations to use? (IB Chem)

Dyck paths with extra diagonals from valleys (Laser construction)

What makes a man succeed?

Sliceness of knots

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

Co-worker has annoying ringtone

How to pronounce 伝統色

What is an "asse" in Elizabethan English?

Project Euler #1 in C++

One-one communication

How to run automated tests after each commit?

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Crossing US/Canada Border for less than 24 hours

Where is the Data Import Wizard Error Log

macOS: Name for app shortcut screen found by pinching with thumb and three fingers

How could we fake a moon landing now?

How many time has Arya actually used Needle?

A letter with no particular backstory



Add Custom Validation Rule Magento 2 Validate.js



Planned maintenance scheduled April 23, 2019 at 23:30UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Custom form validation using ajax.updater in magentoCombined form fields validationValidation not working on custom field at register.phtmlCustom checkboxes form Validation - MagentoHow to override Catalog Price Rules?Use cases for different JS init methodsHow to add custom js form validation with custom error message in magento2?Magento 2 add custom validation ruleMagento 2 Custom Validation RuleMagento 2.2.5: How to validate shipping address



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am using the following code on a form to use the validation.js library to validate the form. One of the validation files uses ./rules.js to extend the rules used within the validator which I have managed to overwrite. However "validation": is not the file that uses it. Can some body please show me?



I have not set a requirejs config in the module that I am doing this from.



I want to add a basic rule that comes back true or false every time just to start from somewhere.



data-mage-init='"validation": 









share|improve this question




























    1















    I am using the following code on a form to use the validation.js library to validate the form. One of the validation files uses ./rules.js to extend the rules used within the validator which I have managed to overwrite. However "validation": is not the file that uses it. Can some body please show me?



    I have not set a requirejs config in the module that I am doing this from.



    I want to add a basic rule that comes back true or false every time just to start from somewhere.



    data-mage-init='"validation": 









    share|improve this question
























      1












      1








      1








      I am using the following code on a form to use the validation.js library to validate the form. One of the validation files uses ./rules.js to extend the rules used within the validator which I have managed to overwrite. However "validation": is not the file that uses it. Can some body please show me?



      I have not set a requirejs config in the module that I am doing this from.



      I want to add a basic rule that comes back true or false every time just to start from somewhere.



      data-mage-init='"validation": 









      share|improve this question














      I am using the following code on a form to use the validation.js library to validate the form. One of the validation files uses ./rules.js to extend the rules used within the validator which I have managed to overwrite. However "validation": is not the file that uses it. Can some body please show me?



      I have not set a requirejs config in the module that I am doing this from.



      I want to add a basic rule that comes back true or false every time just to start from somewhere.



      data-mage-init='"validation": 






      magento2 validation form-validation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 30 '17 at 8:04









      LM_FieldingLM_Fielding

      7331437




      7331437




















          1 Answer
          1






          active

          oldest

          votes


















          0














          It's hard to answer your question without creating an example. So I suppose that you need to add your custom validation rule into your custom payment method in Magento 2.



          Then, your method render js will look like this:



          /**
          * Copyright © 2017 StackOverflow. All rights reserved.
          * See COPYING.txt for license details.
          */
          /*browser:true*/
          /*global define*/
          define(
          [
          'jquery',
          'ko',
          'Magento_Checkout/js/view/payment/default',
          'mage/validation'
          ],
          function ($, ko, Component)
          'use strict';

          $.validator.addMethod('validate-input-one', function (value)
          return (value === $('#hidden-input-one').val());
          , 'You have to select input 1 before place order.');

          $.validator.addMethod('validate-input-two', function (value)
          return (value === $('#hidden-input-two').val());
          , 'You have to select input 2 before place order.');

          return Component.extend(

          ...

          /**
          * Custompayment form validation
          *
          * @returns Boolean
          */
          validate: function ()
          var form = 'form[data-role=custompayment-form]';
          return $(form).validation() && $(form).validation('isValid');
          ,

          ...

          );

          );


          Now, in your custom payment method template file:



          <input type="text"
          id="input-one"
          name="payment[input-one]"
          data-validate="required:true, 'validate-input-one': true"
          aria-haspopup="false"
          aria-autocomplete="both"
          autocomplete="off"
          class="input-text"/>
          <input type="hidden" id="hidden-input-one" data-bind="value: inputOne" />


          As you see, whenever the value attribute of #hidden-input-one is empty, #input-one will not pass the validation.



          CONCLUSION



          mage/validation is the key.






          share|improve this answer

























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f166907%2fadd-custom-validation-rule-magento-2-validate-js%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It's hard to answer your question without creating an example. So I suppose that you need to add your custom validation rule into your custom payment method in Magento 2.



            Then, your method render js will look like this:



            /**
            * Copyright © 2017 StackOverflow. All rights reserved.
            * See COPYING.txt for license details.
            */
            /*browser:true*/
            /*global define*/
            define(
            [
            'jquery',
            'ko',
            'Magento_Checkout/js/view/payment/default',
            'mage/validation'
            ],
            function ($, ko, Component)
            'use strict';

            $.validator.addMethod('validate-input-one', function (value)
            return (value === $('#hidden-input-one').val());
            , 'You have to select input 1 before place order.');

            $.validator.addMethod('validate-input-two', function (value)
            return (value === $('#hidden-input-two').val());
            , 'You have to select input 2 before place order.');

            return Component.extend(

            ...

            /**
            * Custompayment form validation
            *
            * @returns Boolean
            */
            validate: function ()
            var form = 'form[data-role=custompayment-form]';
            return $(form).validation() && $(form).validation('isValid');
            ,

            ...

            );

            );


            Now, in your custom payment method template file:



            <input type="text"
            id="input-one"
            name="payment[input-one]"
            data-validate="required:true, 'validate-input-one': true"
            aria-haspopup="false"
            aria-autocomplete="both"
            autocomplete="off"
            class="input-text"/>
            <input type="hidden" id="hidden-input-one" data-bind="value: inputOne" />


            As you see, whenever the value attribute of #hidden-input-one is empty, #input-one will not pass the validation.



            CONCLUSION



            mage/validation is the key.






            share|improve this answer





























              0














              It's hard to answer your question without creating an example. So I suppose that you need to add your custom validation rule into your custom payment method in Magento 2.



              Then, your method render js will look like this:



              /**
              * Copyright © 2017 StackOverflow. All rights reserved.
              * See COPYING.txt for license details.
              */
              /*browser:true*/
              /*global define*/
              define(
              [
              'jquery',
              'ko',
              'Magento_Checkout/js/view/payment/default',
              'mage/validation'
              ],
              function ($, ko, Component)
              'use strict';

              $.validator.addMethod('validate-input-one', function (value)
              return (value === $('#hidden-input-one').val());
              , 'You have to select input 1 before place order.');

              $.validator.addMethod('validate-input-two', function (value)
              return (value === $('#hidden-input-two').val());
              , 'You have to select input 2 before place order.');

              return Component.extend(

              ...

              /**
              * Custompayment form validation
              *
              * @returns Boolean
              */
              validate: function ()
              var form = 'form[data-role=custompayment-form]';
              return $(form).validation() && $(form).validation('isValid');
              ,

              ...

              );

              );


              Now, in your custom payment method template file:



              <input type="text"
              id="input-one"
              name="payment[input-one]"
              data-validate="required:true, 'validate-input-one': true"
              aria-haspopup="false"
              aria-autocomplete="both"
              autocomplete="off"
              class="input-text"/>
              <input type="hidden" id="hidden-input-one" data-bind="value: inputOne" />


              As you see, whenever the value attribute of #hidden-input-one is empty, #input-one will not pass the validation.



              CONCLUSION



              mage/validation is the key.






              share|improve this answer



























                0












                0








                0







                It's hard to answer your question without creating an example. So I suppose that you need to add your custom validation rule into your custom payment method in Magento 2.



                Then, your method render js will look like this:



                /**
                * Copyright © 2017 StackOverflow. All rights reserved.
                * See COPYING.txt for license details.
                */
                /*browser:true*/
                /*global define*/
                define(
                [
                'jquery',
                'ko',
                'Magento_Checkout/js/view/payment/default',
                'mage/validation'
                ],
                function ($, ko, Component)
                'use strict';

                $.validator.addMethod('validate-input-one', function (value)
                return (value === $('#hidden-input-one').val());
                , 'You have to select input 1 before place order.');

                $.validator.addMethod('validate-input-two', function (value)
                return (value === $('#hidden-input-two').val());
                , 'You have to select input 2 before place order.');

                return Component.extend(

                ...

                /**
                * Custompayment form validation
                *
                * @returns Boolean
                */
                validate: function ()
                var form = 'form[data-role=custompayment-form]';
                return $(form).validation() && $(form).validation('isValid');
                ,

                ...

                );

                );


                Now, in your custom payment method template file:



                <input type="text"
                id="input-one"
                name="payment[input-one]"
                data-validate="required:true, 'validate-input-one': true"
                aria-haspopup="false"
                aria-autocomplete="both"
                autocomplete="off"
                class="input-text"/>
                <input type="hidden" id="hidden-input-one" data-bind="value: inputOne" />


                As you see, whenever the value attribute of #hidden-input-one is empty, #input-one will not pass the validation.



                CONCLUSION



                mage/validation is the key.






                share|improve this answer















                It's hard to answer your question without creating an example. So I suppose that you need to add your custom validation rule into your custom payment method in Magento 2.



                Then, your method render js will look like this:



                /**
                * Copyright © 2017 StackOverflow. All rights reserved.
                * See COPYING.txt for license details.
                */
                /*browser:true*/
                /*global define*/
                define(
                [
                'jquery',
                'ko',
                'Magento_Checkout/js/view/payment/default',
                'mage/validation'
                ],
                function ($, ko, Component)
                'use strict';

                $.validator.addMethod('validate-input-one', function (value)
                return (value === $('#hidden-input-one').val());
                , 'You have to select input 1 before place order.');

                $.validator.addMethod('validate-input-two', function (value)
                return (value === $('#hidden-input-two').val());
                , 'You have to select input 2 before place order.');

                return Component.extend(

                ...

                /**
                * Custompayment form validation
                *
                * @returns Boolean
                */
                validate: function ()
                var form = 'form[data-role=custompayment-form]';
                return $(form).validation() && $(form).validation('isValid');
                ,

                ...

                );

                );


                Now, in your custom payment method template file:



                <input type="text"
                id="input-one"
                name="payment[input-one]"
                data-validate="required:true, 'validate-input-one': true"
                aria-haspopup="false"
                aria-autocomplete="both"
                autocomplete="off"
                class="input-text"/>
                <input type="hidden" id="hidden-input-one" data-bind="value: inputOne" />


                As you see, whenever the value attribute of #hidden-input-one is empty, #input-one will not pass the validation.



                CONCLUSION



                mage/validation is the key.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 14 '18 at 11:41









                Teja Bhagavan Kollepara

                2,99241949




                2,99241949










                answered Mar 30 '17 at 8:26









                Toan NguyenToan Nguyen

                2,0121138




                2,0121138



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f166907%2fadd-custom-validation-rule-magento-2-validate-js%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Sum ergo cogito? 1 nng

                    三茅街道4182Guuntc Dn precexpngmageondP