Using Parsley.js with Meteor using HTML Code

2019-05-11 21:09发布

问题:

I have been trying to use Parsley.js with Meteor, I can get it to work with a JS using a rendered function but I've had no luck when I use the HTML code approach. Example code is given below:

<form class="form-horizontal frmParsley" role="form" parsley-validate>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputEmail3" placeholder="Name" parsley-trigger="change" parsley-minlength="5" required />
</div>
</div>
</form>

回答1:

Per the docs at http://parsleyjs.org/documentation.html#javascript:

Parsleys DOM-API is great. But not so great for complex forms, or dynamically generated forms.

Meteor's templates are dynamically generated forms. Therefore you need to initialize Parsley via JavaScript, in a rendered function.

There might be a way to initialize Parsley on rendered as if it were an initial page load, and therefore get it to recognize and parse the parsley- attributes, but such a method is undocumented and might be unreliable in the future.