Skip to content

Instantly share code, notes, and snippets.

@Raphhh
Created January 26, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raphhh/ec4be94ae0211a0ae498a3c106018df4 to your computer and use it in GitHub Desktop.
Save Raphhh/ec4be94ae0211a0ae498a3c106018df4 to your computer and use it in GitHub Desktop.
Display error messages of the html validation in a symphony form
$('input,select,textarea', $context).on('invalid', function(evt) {
var $this = $(this);
setErrorMessage($this, $this.data('validation-message') || this.validationMessage);
});
function setErrorMessage($field, message) {
var $parent = $field.closest('div:not(.input-group)');
var $messageContainer = $parent.find('.help-block');
if (!$messageContainer.length) {
$messageContainer = $('<span class="help-block"><ul class="list-unstyled"></ul></span>');
$parent.append($messageContainer);
}
$messageContainer.find('ul').html('<li><span class="glyphicon glyphicon-exclamation-sign"></span> ' + message + '</li>');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment