0

I had a input field in my form that have the following class:

class="form-group field-sale-first_name required"

and after client side validation it can have one of two different classes added to it.

class="form-group field-sale-first_name required has-success"

or

class="form-group field-sale-first_name required has-error"

I'm trying to catch when this class has success of error status with jQuery method hasClass() but always getting True even when the .has-error or the has-success are not there.

<form id="checkout-form" action="/site/checkout" method="post">

    <div class="form-group field-sale-first_name required">
    <input type="text" id="sale-first_name" class="form-control" name="Sale[first_name]" placeholder="First Name">

and the script:

clientValidationStatus = (function() {
    if ($("form-group.field-sale-first_name.required").hasClass(".has-success)) {
      alert("Success");
    }
  })();

Could someone give a hint of how to get this change?

Thanks in advance.

Alessandro Resta
  • 1,102
  • 1
  • 19
  • 26

1 Answers1

2

You are missing hasClass syntax hasClass("has-success") and for form-group

  clientValidationStatus = (function() {
        if ($(".form-group.field-sale-first_name.required").hasClass("has-success")) {
          alert("Success");
        }
      })();
Akki619
  • 2,386
  • 6
  • 26
  • 56