OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 <link rel="import" href="../polymer/polymer.html"> |
| 11 <link rel="import" href="../iron-input/iron-input.html"> |
| 12 <link rel="import" href="../iron-flex-layout/classes/iron-flex-layout.html"> |
| 13 <link rel="import" href="../iron-validatable-behavior/iron-validatable-behavior.
html"> |
| 14 <link rel="import" href="date-validator.html"> |
| 15 |
| 16 <dom-module id="date-input"> |
| 17 |
| 18 <style> |
| 19 :host { |
| 20 display: inline-block; |
| 21 } |
| 22 |
| 23 span { |
| 24 @apply(--paper-input-container-font); |
| 25 opacity: 0.33; |
| 26 text-align: center; |
| 27 } |
| 28 |
| 29 input { |
| 30 position: relative; /* to make a stacking context */ |
| 31 outline: none; |
| 32 box-shadow: none; |
| 33 padding: 0; |
| 34 width: 100%; |
| 35 background: transparent; |
| 36 border: none; |
| 37 color: var(--paper-input-container-input-color, --primary-text-color); |
| 38 text-align: center; |
| 39 |
| 40 @apply(--paper-font-subhead); |
| 41 @apply(--paper-input-container-input); |
| 42 } |
| 43 |
| 44 </style> |
| 45 |
| 46 <template> |
| 47 <date-validator id="validator"></date-validator> |
| 48 |
| 49 <span aria-hidden id="monthLabel" hidden>Month</span> |
| 50 <span aria-hidden id="yearLabel" hidden>Year</span> |
| 51 |
| 52 <div class="horizontal layout"> |
| 53 <input is="iron-input" |
| 54 aria-labelledby$="[[_computeAriaLabel(ariaLabelPrefix,'monthLabel')]]" |
| 55 required$="[[required]]" |
| 56 maxlength="2" |
| 57 bind-value="{{month}}" |
| 58 placeholder="MM" |
| 59 allowed-pattern="[0-9]" |
| 60 prevent-invalid-input |
| 61 autocomplete="cc-exp-month" |
| 62 type="tel" |
| 63 class="flex"> |
| 64 <span>/</span> |
| 65 <input is="iron-input" |
| 66 aria-labelledby$="[[_computeAriaLabel(ariaLabelPrefix,'yearLabel')]]" |
| 67 required$="[[required]]" |
| 68 maxlength="2" |
| 69 bind-value="{{year}}" |
| 70 placeholder="YY" |
| 71 allowed-pattern="[0-9]" |
| 72 prevent-invalid-input |
| 73 autocomplete="cc-exp-year" |
| 74 type="tel" |
| 75 class="flex"> |
| 76 </div> |
| 77 </template> |
| 78 |
| 79 </dom-module> |
| 80 |
| 81 <script> |
| 82 Polymer({ |
| 83 |
| 84 is: 'date-input', |
| 85 |
| 86 behaviors: [ |
| 87 Polymer.IronValidatableBehavior |
| 88 ], |
| 89 |
| 90 properties: { |
| 91 /** |
| 92 * Set to true to mark the input as required. |
| 93 */ |
| 94 required: { |
| 95 type: Boolean, |
| 96 value: false |
| 97 }, |
| 98 |
| 99 /** |
| 100 * The month component of the date displayed. |
| 101 */ |
| 102 month: { |
| 103 type: String |
| 104 }, |
| 105 |
| 106 /** |
| 107 * The year component of the date displayed. |
| 108 */ |
| 109 year: { |
| 110 type: String |
| 111 }, |
| 112 |
| 113 /** |
| 114 * The date object used by the validator. Has two properties, month and ye
ar. |
| 115 */ |
| 116 date: { |
| 117 notify: true, |
| 118 type: Object |
| 119 }, |
| 120 |
| 121 validator: { |
| 122 type: String, |
| 123 value: 'date-validator' |
| 124 }, |
| 125 |
| 126 ariaLabelPrefix: { |
| 127 type:String |
| 128 } |
| 129 |
| 130 }, |
| 131 |
| 132 observers: [ |
| 133 '_computeDate(month,year)' |
| 134 ], |
| 135 |
| 136 _computeDate: function(month, year) { |
| 137 // Months are 0-11. |
| 138 this.date = {month: month, year: year}; |
| 139 this.fire('dateChanged', this.date); |
| 140 }, |
| 141 |
| 142 validate: function() { |
| 143 // Empty, non-required input is valid. |
| 144 if (!this.required && this.month == '' && this.year == '') { |
| 145 return true; |
| 146 } |
| 147 this.invalid = !this.$.validator.validate(this.date); |
| 148 this.fire('iron-input-validate'); |
| 149 return !this.invalid; |
| 150 }, |
| 151 |
| 152 _computeAriaLabel: function(dateLabel, monthLabel) { |
| 153 return dateLabel + ' ' + monthLabel; |
| 154 } |
| 155 |
| 156 }); |
| 157 </script> |
OLD | NEW |