I'm trying to add Parsley validation to a set of radio buttons contained within a Bootstrap 3 btn-group.
The issue is that the error wrapper that parsley injects (in my case set to a span) is appearing in between the two options (which are contained within a label) rather that outside the btn-group div.
This is illustrated in the sample below:
<div class="form-group">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default"><input type="radio" name="BuyAgain" value="True" data-parsley-required="true" data-parsley-multiple="BuyAgain" data-parsley-id="3282">Yes</label>
<span class="help-block" id="parsley-id-multiple-BuyAgain"></span>
<label class="btn btn-default"><input type="radio" name="BuyAgain" value="False" data-parsley-required="true" data-parsley-multiple="BuyAgain" data-parsley-id="3282">No</label>
</div>
</div>
Any suggestions as to how I can remedy this?
After digging through the source code, I noticed there was an "errorsContainer" option available when initialising Parsley.
After changing the initalisation function to:
$(".validate-form").parsley({
successClass: "has-success",
errorClass: "has-error",
classHandler: function (el) {
return el.$element.closest(".form-group");
},
errorsContainer: function (el) {
return el.$element.closest(".form-group");
},
errorsWrapper: "<span class='help-block'></span>",
errorTemplate: "<span></span>"
});
I now get the resulting html:
<div class="form-group">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default"><input type="radio" name="BuyAgain" value="True" data-parsley-required="true" data-parsley-multiple="BuyAgain" data-parsley-id="1481">Yes</label>
<label class="btn btn-default"><input type="radio" name="BuyAgain" value="False" data-parsley-required="true" data-parsley-multiple="BuyAgain" data-parsley-id="1481">No</label>
</div>
<span class="help-block" id="parsley-id-multiple-BuyAgain"></span>
</div>
Another response, which is equivqlent to @Jon response is to add a the data-parsley-errors-container attribute to your form.
<form data-parsley-errors-container=".form-group" data-parsley-validate="">
...
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With