|
| 1 | +<div ng-controller="AppCtrl" layout="column" ng-cloak> |
| 2 | + |
| 3 | + <md-content layout-padding> |
| 4 | + <form name="userForm"> |
| 5 | + <div layout="row" layout-xs="column" layout-sm="column" layout-align="space-between center"> |
| 6 | + <div flex-gt-sm="80"> |
| 7 | + <p> |
| 8 | + The <code>md-input-container</code> gives you the flexibility to display your messages |
| 9 | + using many standard angular directives. |
| 10 | + </p> |
| 11 | + |
| 12 | + <p> |
| 13 | + For instance, toggle the switch |
| 14 | + |
| 15 | + <span hide-xs hide-sm>to the right</span> |
| 16 | + <span hide-gt-sm>below</span> |
| 17 | + |
| 18 | + to see the messages switch between some custom hints, and the actual error messages. |
| 19 | + Note that some of the <code>ng-messages</code> containers use <code>ngIf</code> while |
| 20 | + others use <code>ng-show</code> or <code>ng-hide</code>. |
| 21 | + </p> |
| 22 | + </div> |
| 23 | + |
| 24 | + <md-input-container> |
| 25 | + <md-switch ng-model="showHints">Showing {{showHints ? "Hints" : "Errors"}}</md-switch> |
| 26 | + </md-input-container> |
| 27 | + </div> |
| 28 | + |
| 29 | + <div layout-gt-sm="row"> |
| 30 | + |
| 31 | + <md-input-container class="md-block" flex-gt-sm> |
| 32 | + <label>Name</label> |
| 33 | + <input md-maxlength="30" required name="name" ng-model="user.name" /> |
| 34 | + |
| 35 | + <div class="hint" ng-if="showHints">Tell us what we should call you!</div> |
| 36 | + |
| 37 | + <div ng-messages="userForm.name.$error" ng-if="!showHints"> |
| 38 | + <div ng-message="required">Name is required.</div> |
| 39 | + <div ng-message="md-maxlength">The name has to be less than 30 characters long.</div> |
| 40 | + </div> |
| 41 | + </md-input-container> |
| 42 | + |
| 43 | + <div flex="5" hide-xs hide-sm> |
| 44 | + <!-- Spacer //--> |
| 45 | + </div> |
| 46 | + |
| 47 | + <md-input-container class="md-block" flex-gt-sm> |
| 48 | + <label>Social Security Number</label> |
| 49 | + <input name="social" ng-model="user.social" ng-pattern="/^[0-9]{3}-[0-9]{2}-[0-9]{4}$/" /> |
| 50 | + |
| 51 | + <div class="hint" ng-if="showHints">###-##-####</div> |
| 52 | + |
| 53 | + <div ng-messages="userForm.social.$error" ng-if="!showHints"> |
| 54 | + <div ng-message="pattern">###-##-#### - Please enter a valid SSN.</div> |
| 55 | + </div> |
| 56 | + </md-input-container> |
| 57 | + |
| 58 | + </div> |
| 59 | + |
| 60 | + <div layout-gt-sm="row"> |
| 61 | + |
| 62 | + <md-input-container class="md-block" flex-gt-sm> |
| 63 | + <label>Email</label> |
| 64 | + <input name="email" ng-model="user.email" |
| 65 | + required minlength="10" maxlength="100" ng-pattern="/^.+@.+\..+$/" /> |
| 66 | + |
| 67 | + <div class="hint" ng-show="showHints">How can we reach you?</div> |
| 68 | + |
| 69 | + <div ng-messages="userForm.email.$error" ng-hide="showHints"> |
| 70 | + <div ng-message-exp="['required', 'minlength', 'maxlength', 'pattern']"> |
| 71 | + Your email must be between 10 and 100 characters long and look like an e-mail address. |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + </md-input-container> |
| 75 | + |
| 76 | + <div flex="5" hide-xs hide-sm> |
| 77 | + <!-- Spacer //--> |
| 78 | + </div> |
| 79 | + |
| 80 | + <md-input-container class="md-block" flex-gt-sm> |
| 81 | + <label>Phone Number</label> |
| 82 | + <input name="phone" ng-model="user.phone" ng-pattern="/^([0-9]{3}) [0-9]{3}-[0-9]{4}$/" /> |
| 83 | + |
| 84 | + <div class="hint" ng-show="showHints">(###) ###-####</div> |
| 85 | + |
| 86 | + <div ng-messages="userForm.phone.$error" ng-hide="showHints"> |
| 87 | + <div ng-message="pattern">(###) ###-#### - Please enter a valid phone number.</div> |
| 88 | + </div> |
| 89 | + </md-input-container> |
| 90 | + |
| 91 | + <style> |
| 92 | + /* |
| 93 | + * The Material demos system does not currently allow targeting the body element, so this |
| 94 | + * must go here in the HTML. |
| 95 | + */ |
| 96 | + body[dir=rtl] .hint { |
| 97 | + right: 2px; |
| 98 | + left: auto; |
| 99 | + } |
| 100 | + </style> |
| 101 | + </div> |
| 102 | + |
| 103 | + </form> |
| 104 | + </md-content> |
| 105 | + |
| 106 | +</div> |
0 commit comments