JSFiddle - React, Tailwind, and code Playground
by thatmarvin
HTML
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
<div ng-app="app">
<form name="FooForm">
<div ng-controller="TotalController">
<div class="control-group" error-on="price" ng-class="{ error: FooForm.price.$invalid }">
<label class="control-label">Price</label>
<input type="number" min=0 name="price" ng-model="price" ng-change="updateTotal()" />
</div>
<div class="control-group" error-on="salesTax" ng-class="{ error: }">
<label class="control-label">Sales Tax</label>
<input type="number" min=0 name="salesTax" ng-model="salesTax" ng-change="updateTotal()" />
</div>
<div class="control-group" error-on='total' ng-class="{ error: FooForm.total.$invalid }">
<label class="control-label">Total (Min: 100)</label>
<input type="number" min=100 name="total" disabled ng-model="total" ng-init="total=0" />
</div>
</div>
</form>
</div>
JavaScript
var app = angular.module('app', []);
app.directive('errorOn', function ($parse) {
return {
link: function (scope, el, attrs) {
// Say attrs.errorOn === 'price', how do I access "price"'s
// ngmodel.$valid from here?
}
};
});
function TotalController($scope) {
$scope.updateTotal = function () {
var total = parseFloat($scope.price || 0) + parseFloat($scope.salesTax || 0);
$scope.total = total;
}
}