Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
remove tag from title
Source Link
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

How to add Jquery Validation to Custom form and set error to field in Drupal 8 (D8)?

I want to implement client side validation using jQuery on my custom form.

I have enabled clientside validation contributed module

I have successfully attached custom js file using following code:

 $form['#attached']['library'][] = 'custom_form/cl-validation';

And in the JS file I have written below code:

(function ($, Drupal) {
  Drupal.behaviors.custom_form = {
    attach: function (context, settings) {
        
        var selectedCountry = ''
        
        $("#country").change(function(){
          selectedCountry = $(this).children("option:selected").val();
         
        });
        
                
        $('#user-number-value').keyup(function(){   
              $(this).val($(this).val().replace(/(\d{2})|([a-z]{2})\-?/,'$1-'))
        });
        
         $("input#user-number-value").focus(function() { 
            if(selectedCountry == undefined || selectedCountry == '') {
                $('#user-number-value').va('')
               // I want mark country dropdown as red and show a error
            }
        });
        
        
    }
  };
})(jQuery, Drupal);

I am not getting how to do this using jquery and stop form submission.

PleaseAny help me?

How to add Jquery Validation to Custom form and set error to field in Drupal 8 (D8)?

I want to implement client side validation using jQuery on my custom form.

I have enabled clientside validation contributed module

I have successfully attached custom js file using following code:

 $form['#attached']['library'][] = 'custom_form/cl-validation';

And in the JS file I have written below code:

(function ($, Drupal) {
  Drupal.behaviors.custom_form = {
    attach: function (context, settings) {
        
        var selectedCountry = ''
        
        $("#country").change(function(){
          selectedCountry = $(this).children("option:selected").val();
         
        });
        
                
        $('#user-number-value').keyup(function(){   
              $(this).val($(this).val().replace(/(\d{2})|([a-z]{2})\-?/,'$1-'))
        });
        
         $("input#user-number-value").focus(function() { 
            if(selectedCountry == undefined || selectedCountry == '') {
                $('#user-number-value').va('')
               // I want mark country dropdown as red and show a error
            }
        });
        
        
    }
  };
})(jQuery, Drupal);

I am not getting how to do this using jquery and stop form submission.

Please help me

How to add Jquery Validation to Custom form and set error to field?

I want to implement client side validation using jQuery on my custom form.

I have enabled clientside validation contributed module

I have successfully attached custom js file using following code:

 $form['#attached']['library'][] = 'custom_form/cl-validation';

And in the JS file I have written below code:

(function ($, Drupal) {
  Drupal.behaviors.custom_form = {
    attach: function (context, settings) {
        
        var selectedCountry = ''
        
        $("#country").change(function(){
          selectedCountry = $(this).children("option:selected").val();
         
        });
        
                
        $('#user-number-value').keyup(function(){   
              $(this).val($(this).val().replace(/(\d{2})|([a-z]{2})\-?/,'$1-'))
        });
        
         $("input#user-number-value").focus(function() { 
            if(selectedCountry == undefined || selectedCountry == '') {
                $('#user-number-value').va('')
               // I want mark country dropdown as red and show a error
            }
        });
        
        
    }
  };
})(jQuery, Drupal);

I am not getting how to do this using jquery and stop form submission.

Any help?

deleted 29 characters in body
Source Link
Akki
  • 381
  • 5
  • 19

I want to implement client side validation using jQuery on my custom form.

I have enabled clientside validation contributed module

I have successfully attached custom js file using following code:

 $form['#attached']['library'][] = 'custom_form/cl-validation';

And in the JS file I have written below code:

(function ($, Drupal) {
  Drupal.behaviors.custom_form = {
    attach: function (context, settings) {
        
        var selectedCountry = ''
        
        $("#country").change(function(){
          selectedCountry = $(this).children("option:selected").val();
         
        });
        
                
        $('#user-number-value').keyup(function(){   
              $(this).val($(this).val().replace(/(\d{2})|([a-z]{2})\-?/,'$1-'))
        });
        
         $("input##user"input#user-number-value").focus(function() { 
            if(selectedCountry == undefined || selectedCountry == '') {
                $('#edit-field-customer'#user-number-reseller-i-0-value').va('')
               // I want mark country dropdown as red and show a error
            }
        });
        
        
    }
  };
})(jQuery, Drupal);

I am not getting how to do this using jquery and stop form submission.

Please help me

I want to implement client side validation using jQuery on my custom form.

I have enabled clientside validation contributed module

I have successfully attached custom js file using following code:

 $form['#attached']['library'][] = 'custom_form/cl-validation';

And in the JS file I have written below code:

(function ($, Drupal) {
  Drupal.behaviors.custom_form = {
    attach: function (context, settings) {
        
        var selectedCountry = ''
        
        $("#country").change(function(){
          selectedCountry = $(this).children("option:selected").val();
         
        });
        
                
        $('#user-number-value').keyup(function(){   
              $(this).val($(this).val().replace(/(\d{2})|([a-z]{2})\-?/,'$1-'))
        });
        
         $("input##user-number-value").focus(function() { 
            if(selectedCountry == undefined || selectedCountry == '') {
                $('#edit-field-customer-number-reseller-i-0-value').va('')
               // I want mark country dropdown as red and show a error
            }
        });
        
        
    }
  };
})(jQuery, Drupal);

I am not getting how to do this using jquery and stop form submission.

Please help me

I want to implement client side validation using jQuery on my custom form.

I have enabled clientside validation contributed module

I have successfully attached custom js file using following code:

 $form['#attached']['library'][] = 'custom_form/cl-validation';

And in the JS file I have written below code:

(function ($, Drupal) {
  Drupal.behaviors.custom_form = {
    attach: function (context, settings) {
        
        var selectedCountry = ''
        
        $("#country").change(function(){
          selectedCountry = $(this).children("option:selected").val();
         
        });
        
                
        $('#user-number-value').keyup(function(){   
              $(this).val($(this).val().replace(/(\d{2})|([a-z]{2})\-?/,'$1-'))
        });
        
         $("input#user-number-value").focus(function() { 
            if(selectedCountry == undefined || selectedCountry == '') {
                $('#user-number-value').va('')
               // I want mark country dropdown as red and show a error
            }
        });
        
        
    }
  };
})(jQuery, Drupal);

I am not getting how to do this using jquery and stop form submission.

Please help me

Source Link
Akki
  • 381
  • 5
  • 19

How to add Jquery Validation to Custom form and set error to field in Drupal 8 (D8)?

I want to implement client side validation using jQuery on my custom form.

I have enabled clientside validation contributed module

I have successfully attached custom js file using following code:

 $form['#attached']['library'][] = 'custom_form/cl-validation';

And in the JS file I have written below code:

(function ($, Drupal) {
  Drupal.behaviors.custom_form = {
    attach: function (context, settings) {
        
        var selectedCountry = ''
        
        $("#country").change(function(){
          selectedCountry = $(this).children("option:selected").val();
         
        });
        
                
        $('#user-number-value').keyup(function(){   
              $(this).val($(this).val().replace(/(\d{2})|([a-z]{2})\-?/,'$1-'))
        });
        
         $("input##user-number-value").focus(function() { 
            if(selectedCountry == undefined || selectedCountry == '') {
                $('#edit-field-customer-number-reseller-i-0-value').va('')
               // I want mark country dropdown as red and show a error
            }
        });
        
        
    }
  };
})(jQuery, Drupal);

I am not getting how to do this using jquery and stop form submission.

Please help me