Last active
August 29, 2015 14:23
-
-
Save laughingman7743/5bebdd61ef19a2703388 to your computer and use it in GitHub Desktop.
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
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css'); |
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="container"> | |
<form class="form-horizontal"> | |
<h1>Form</h1> | |
<div class="form-group"> | |
<label class="col-sm-2 control-label" for="inputEmail">Email</label> | |
<div class="col-sm-10" data-bind="validationElement: email"> | |
<input type="text" id="inputEmail" class="form-control" placeholder="Email" data-bind="value: email"/> | |
<p class="text-danger" data-bind="validationMessage: email"></p> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label class="col-sm-2 control-label" for="inputPassword">Password</label> | |
<div class="col-sm-10" data-bind="validationElement: password"> | |
<input type="password" id="inputPassword" class="form-control" placeholder="Password" data-bind="value: password"/> | |
<p class="text-danger" data-bind="validationMessage: password"></p> | |
</div> | |
</div> | |
<div class="form-group well well-lg" > | |
<div class="col-sm-offset-2 col-sm-10"> | |
<button type="submit" class="btn btn-primary">Submit</button> | |
<button type="button" class="btn">Cancel</button> | |
</div> | |
</div> | |
</form> | |
</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
$(function() { | |
function myViewModel() { | |
var self = this; | |
self.email = ko.observable().extend({ | |
required: { | |
message: 'required' | |
}, | |
email: { | |
message: 'invalid format' | |
} | |
}); | |
self.password = ko.observable().extend({ | |
required: { | |
message: 'required' | |
}, | |
minLength: { | |
params: 6, | |
message: 'too short' | |
} | |
}); | |
} | |
ko.validation.init({ | |
insertMessages: false, | |
decorateElement: true, | |
errorElementClass: 'has-error' | |
}); | |
var viewModel = ko.validatedObservable(new myViewModel()); | |
ko.applyBindings(viewModel); | |
}) |
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
name: KnockoutJS Validation Sample 1 | |
authors: | |
- laughingman7743 | |
resources: | |
- http://knockoutjs.com/downloads/knockout-3.3.0.js | |
- http://code.jquery.com/jquery-2.1.4.min.js | |
- http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js | |
- http://cdnjs.cloudflare.com/ajax/libs/knockout-validation/2.0.3/knockout.validation.min.js | |
normalize_css: no | |
wrap: b | |
panel_js: 0 | |
panel_css: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment