8

Validation is not working properly. Its always shows This field is required. Even if I don't touch this field. Why?

<div class="form-group">
 <label class="control-label col-sm-4">Description<span class="required"> * </span></label>
  <div class="col-sm-8">
    <input type="text" name="name" data-required="1" class="form-control" aria-required="true" aria-invalid="true" aria-describedby="name-error">
      <span id="name-error" class="help-block help-block-error">This field is required.</span>
  </div>
</div>
Alper Ebicoglu
  • 8,884
  • 1
  • 49
  • 55
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197

2 Answers2

1

You could try adding the name="name" to the label.

Also add for="name" to the label.

Jeff Mattson
  • 394
  • 3
  • 9
  • It also looks like you have `class="required"` on the label. I may mis-understand your question but doesn't that make the field required? Of course only if you associate the label with the input field by adding the `for="name"` above. If you don't want it to be a required field remove the `class="required"`. – Jeff Mattson Sep 12 '17 at 19:38
0

Label's "for" attribute is bound to HTML element by element_id.

Remove the class="required" on the label and add required attribute to the input field if is needed.

<label for="element_id">
<input type="text" id="element_id" required>
<div class="help-block with-errors"></div>
darklion
  • 1
  • 2