0

While doing validation of form fields, I can validating all fields using required attibutes parsley.js. Except the file field. I couldn't able to validate file upload field. When i check the code using developer tool (inspect element) in Firefox there is no classes added for the validation at filed field. Remaining text field, Select fields are having the additional parsley classes.

My HTML Code:

<input type="file" id="uploadDox" name="filename" class="form-control" required>

Parsley form submit JS code:

var form_update = $form_update.parsley();
  $btn_form_update.on('click', function(evt) {
     evt.preventDefault();
    if ( form_update.validate() ) {
      loading( $(this), true );
      $form_update_trainingDocs.submit();
    }
  });

what mistake i did there. How can i validate the file field using parsley.js. Please give your suggestion on this.

Thanks in advance :-)

Sathish Chelladurai
  • 670
  • 1
  • 8
  • 23

1 Answers1

1

If you make the simple effort of providing a minimal working example (like this), you would easily see that parsley handles required for files just fine.

So the error is in your code / HTML. I imagine that your issue is calling validate() instead of validate(true), the former does not enforce requiredness.

Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
  • @Marc-Anre Lafortune Thx for your answer. I tried this. but no luck. If i removed the line // evt.preventDefault(); from JS code. Then the parsley validation is working for file field. I want to know why when i am using evt.preventDefault(). It doesn't validate. This problem only for file field not other fields like text, select. – Sathish Chelladurai Sep 08 '15 at 06:01
  • 1
    When I update the latest version of Parsley.js The file field validation is working fine.. :-) – Sathish Chelladurai Sep 08 '15 at 11:03