Validate max file upload size with parsley.js

前端 未结 3 1730
一个人的身影
一个人的身影 2021-01-25 19:10

I\'m using parsley.js in a USP Pro form in Wordpress. The validation works, in general, but now I\'m trying to validate the max file size and I don\'t really understand how to d

3条回答
  •  感情败类
    2021-01-25 19:29

    There are a few remarks:

    1. That code appears to be from Parsley 1.* (see documentation), which is now deprecated.
    2. Even though it appears to be from Parsley 1.*, that code does not follow the correct structure for a custom validator (see an example).
    3. Parsley excludes input[type=file] by default. Just for this, your code is never executed.
    4. The custom validator should be bind by parsley-filemaxsize instead of data-filemaxsize

    I've managed to tweeak the code, and the solution is below. You can also check the working jsfiddle.

    Please be aware: I've spent some time trying to convert this code into Parsley 2.* . However, I don't think you can use Parsley 2.* since the Custom Validators only recieve the value and the requirement and you need the parsleyField.$element to verify the file size.

提交回复
热议问题