Skip to content

Instantly share code, notes, and snippets.

@ChrisAichinger
Created June 18, 2015 23:23
Show Gist options
  • Save ChrisAichinger/9b0805e66607177379e1 to your computer and use it in GitHub Desktop.
Save ChrisAichinger/9b0805e66607177379e1 to your computer and use it in GitHub Desktop.
<form class="form-horizontal" id="comment-form" ng-show="CommentAPI.connected">
<fieldset>
<legend>Post a comment</legend>
<div class="form-group">
<label for="postcomment-homepage" class="col-lg-2 control-label">Homepage</label>
<div class="col-lg-10">
<input class="form-control" id="postcomment-homepage" placeholder="Homepage" type="url"
maxlength="150" ng-model="comment.homepage">
</div>
</div>
...
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary"
ng-click="submit(comment)"
ng-disabled="submitting">Submit Comment</button>
<img src='{{ path }}/spinner.gif' class="submitting-spinner" ng-show="submitting" />
</div>
</div>
</fieldset>
</form>
app.controller('PostCommentController', [
'$scope', '$filter', '$sanitize', 'Config', 'Comment',
function($scope, $filter, $sanitize, Config, Comment)
{
$scope.comment = {
homepage: null,
};
$scope.submit = function(comment) {
# Here, comment.homepage is either null (if the input was never touched)
# a valid url (url entered) or undefined (entered `javascript:` url).
# Ideally, I'd like to validate the input so that either blank or a valid
# URL are valid, or angular validation fails (and 'undefined' can't happen
# here any more.)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment