I would like to validate the form using parsley js and display errors (if any) using the twitter tooltip.
I read a link about integrating twitter bootstrap with parsley, and this question about the stack surface about EventListeners. However, I still cannot display error messages.
The way I implemented it
...
<input id="id_email" name="email" required=True parsley-type="email">
<button type="submit" onclick="javascript:$('#id_email').parsley(parsleyOptions); ">Next</button>
...
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="{% static "js/bootstrap.min.js" %}"></script>
<script type="text/javascript" src="{% static "js/parsley/parsley.js"%}"></script>
...
<script>
var parsleyOptions = {
successClass: 'has-success',
errorClass: 'has-error',
errors: {
classHandler: function(el) {
return el.parent();
},
errorsWrapper: '',
errorElem: ''
},
listeners: {
onFieldError: function (elem, constraints, parsleyField) {
elem.tooltip({
animation: false,
container: 'body',
placement: 'top',
title: elem.data('error-message')
});
},
onFieldSuccess: function(elem, constraints, parsleyField) {
elem.tooltip('destroy');
}
}
};
</script>
...
The tooltip does not start with an error in the form field (even with an empty field, the error does not occur). How can I get parsley to launch a tooltip?
Side notes:
- The code for 'parsleyOptions' is taken from here
- All js files available
- static tooltip above input field works
- parsley js , div