Created
January 26, 2017 17:03
-
-
Save Raphhh/ec4be94ae0211a0ae498a3c106018df4 to your computer and use it in GitHub Desktop.
Display error messages of the html validation in a symphony form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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