<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<body ng-controller="MyController">
<form name="myForm" ng-submit="onsubmit()" novalidate>
<div>
<label for="name">名前:</label><br />
<input id="name" name="name" type="text" ng-model="user.name"
required ng-minlength="2" ng-maxlength="10" />
<span ng-show="myForm.name.$error.required">
名前は必須です。</span>
<span ng-show="myForm.name.$error.minlength">
名前は2文字以上で入力してください。</span>
<span ng-show="myForm.name.$error.maxlength">
名前は10文字以内で入力してください。</span>
</div>
<div>
<label for="age">年齢:</label><br />
<input id="age" name="age" type="number" ng-model="user.age"
required min="20" max="60" />
<span ng-show="myForm.age.$error.required">
年齢は必須です。</span>
<span ng-show="myForm.age.$error.min">
年齢は20以上で入力してください。</span>
<span ng-show="myForm.age.$error.max">
年齢は60以下で入力してください。</span>
</div>
<div>
<label for="mail">メールアドレス:</label><br />
<input id="mail" name="mail" type="email" ng-model="user.mail"
required />
<span ng-show="myForm.mail.$error.required">
メールアドレスは必須です。</span>
<span ng-show="myForm.mail.$error.email">
メールアドレスは正しい形式で入力してください。</span>
</div>
<div>
<label for="entry">入会希望日:</label><br />
<input id="entry" name="entry" type="date" ng-model="user.entry"
required />
<span ng-show="myForm.entry.$error.required">
入会希望日は必須です。</span>
<span ng-show="myForm.entry.$error.date">
入会希望日は正しい形式で入力してください。</span>
</div>
<label for="memo">備考:</label><br />
<textarea id="memo" name="memo" rows="5" cols="30"
ng-model="user.memo" ng-maxlength="10"></textarea>
<span ng-show="myForm.memo.$error.maxlength">
備考は10文字以内で入力してください。</span>
</div>
<div>
<input type="submit" value="申込"
ng-disabled="myForm.$invalid" />
</div>
</form>
<script>
var app = angular.module('myApp', []);
app.controller('MyController', ['$scope',
function($scope)
{ $scope.onsubmit = function()
{ console.log('名前:' + $scope.user.name);
console.log('年齢:' + $scope.user.age);
console.log('メールアドレス:' + $scope.user.mail);
console.log('入会希望日:' + $scope.user.entry);
console.log('備考:' + $scope.user.memo);
};
}]);
</script>
</body>
</html>
|