Created
September 22, 2015 17:28
-
-
Save vanillajonathan/81234cee3dd023f14191 to your computer and use it in GitHub Desktop.
Input validation with Bootstrap warning
This file contains hidden or 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
<div class="form-group"> | |
<label class="control-label" for="url">URL</label> | |
<input class="form-control" type="url" id="url" placeholder="https://api.example.com/" /> | |
<p class="help-block" id="url-help"></p> | |
</div> |
This file contains hidden or 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
$('#url').on('input', function (e) { | |
if ($(this).val().startsWith("http://")) { | |
$(this).parent().addClass('has-warning'); | |
$('#url-help').text('Note that the communication will not be secure.'); | |
} else { | |
$(this).parent().removeClass('has-warning'); | |
$('#url-help').text(null); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment