|
106 | 106 | <md-table-cell><code>Number</code></md-table-cell>
|
107 | 107 | <md-table-cell>Sets the maxlength and enable the text counter.</md-table-cell>
|
108 | 108 | </md-table-row>
|
| 109 | + |
| 110 | + <md-table-row> |
| 111 | + <md-table-cell>readonly</md-table-cell> |
| 112 | + <md-table-cell><code>Boolean</code></md-table-cell> |
| 113 | + <md-table-cell>Sets the component to read only mode.</md-table-cell> |
| 114 | + </md-table-row> |
| 115 | + </md-table-body> |
| 116 | + </md-table> |
| 117 | + </api-table> |
| 118 | + |
| 119 | + <api-table name="md-autocomplete"> |
| 120 | + <md-table slot="properties"> |
| 121 | + <md-table-header> |
| 122 | + <md-table-row> |
| 123 | + <md-table-head>Name</md-table-head> |
| 124 | + <md-table-head>Type</md-table-head> |
| 125 | + <md-table-head>Description</md-table-head> |
| 126 | + </md-table-row> |
| 127 | + </md-table-header> |
| 128 | + |
| 129 | + <md-table-body> |
| 130 | + <md-table-row> |
| 131 | + <md-table-cell>v-model</md-table-cell> |
| 132 | + <md-table-cell><code>String</code></md-table-cell> |
| 133 | + <md-table-cell>A required model object to bind the value.</md-table-cell> |
| 134 | + </md-table-row> |
| 135 | + |
| 136 | + <md-table-row> |
| 137 | + <md-table-cell>debounce</md-table-cell> |
| 138 | + <md-table-cell><code>Number</code></md-table-cell> |
| 139 | + <md-table-cell>Sets the debounce time. Default <code>1000</code> milliseconds</md-table-cell> |
| 140 | + </md-table-row> |
| 141 | + |
| 142 | + <md-table-row> |
| 143 | + <md-table-cell>fetch</md-table-cell> |
| 144 | + <md-table-cell><code>Function</code></md-table-cell> |
| 145 | + <md-table-cell>Sets the fetch function mdAutocomplete will call after the debounce is reached. Chosing <code>fetch</code> prop <strong>disables</strong> the use of either <code>list</code> and <code>filterList</code> props.</md-table-cell> |
| 146 | + </md-table-row> |
| 147 | + |
| 148 | + <md-table-row> |
| 149 | + <md-table-cell>list</md-table-cell> |
| 150 | + <md-table-cell><code>Array</code></md-table-cell> |
| 151 | + <md-table-cell>Sets an array of possible values. Default <code>[]</code>. MdAutocomplete will only search in this list if it's set. Chosing <code>list</code> prop <strong>disables</strong> the use of <code>fetch</code> prop.</md-table-cell> |
| 152 | + </md-table-row> |
| 153 | + |
| 154 | + <md-table-row> |
| 155 | + <md-table-cell>filter-list</md-table-cell> |
| 156 | + <md-table-cell><code>Function</code></md-table-cell> |
| 157 | + <md-table-cell>Sets a filter function which will be used to filter the <code>list</code> props. Chosing <code>filterList</code> prop <strong>requires</strong> the use of <code>list</code> props and <strong>disables</strong> the use of <code>fetch</code> prop.</md-table-cell> |
| 158 | + </md-table-row> |
| 159 | + |
| 160 | + <md-table-row> |
| 161 | + <md-table-cell>min-chars</md-table-cell> |
| 162 | + <md-table-cell><code>Number</code></md-table-cell> |
| 163 | + <md-table-cell>Sets the minimum number of characters before making opening the autocomplete options or making a request. Default <code>3</code></md-table-cell> |
| 164 | + </md-table-row> |
| 165 | + |
| 166 | + <md-table-row> |
| 167 | + <md-table-cell>prepare-response-data</md-table-cell> |
| 168 | + <md-table-cell><code>Function</code></md-table-cell> |
| 169 | + <md-table-cell>This function will be called once the <code>fetch</code> prop has a response. It can manipulate the data received from the server. The output should always be an <code>Array</code>.</md-table-cell> |
| 170 | + </md-table-row> |
| 171 | + |
| 172 | + <md-table-row> |
| 173 | + <md-table-cell>print-attribute</md-table-cell> |
| 174 | + <md-table-cell><code>String</code></md-table-cell> |
| 175 | + <md-table-cell>This prop will be used to print values on the autocomplete list. It shall match an object key expected on the <code>fetch</code> result list. Default <code>name</code></md-table-cell> |
| 176 | + </md-table-row> |
| 177 | + |
| 178 | + <md-table-row> |
| 179 | + <md-table-cell>query-param</md-table-cell> |
| 180 | + <md-table-cell><code>String</code></md-table-cell> |
| 181 | + <md-table-cell>Sets the query parameter. Example: http//api.com/<strong>q</strong>?=SOMETHING. Default <code>q</code></md-table-cell> |
| 182 | + </md-table-row> |
| 183 | + |
| 184 | + <md-table-row> |
| 185 | + <md-table-cell>disabled</md-table-cell> |
| 186 | + <md-table-cell><code>Boolean</code></md-table-cell> |
| 187 | + <md-table-cell>Disable the input and prevent his actions. Default <code>false</code></md-table-cell> |
| 188 | + </md-table-row> |
| 189 | + |
| 190 | + <md-table-row> |
| 191 | + <md-table-cell>required</md-table-cell> |
| 192 | + <md-table-cell><code>Boolean</code></md-table-cell> |
| 193 | + <md-table-cell>Apply the required rule to style the label with an "*". Default <code>false</code></md-table-cell> |
| 194 | + </md-table-row> |
| 195 | + |
| 196 | + <md-table-row> |
| 197 | + <md-table-cell>placeholder</md-table-cell> |
| 198 | + <md-table-cell><code>String</code></md-table-cell> |
| 199 | + <md-table-cell>Sets the placeholder.</md-table-cell> |
| 200 | + </md-table-row> |
| 201 | + |
| 202 | + <md-table-row> |
| 203 | + <md-table-cell>maxlength</md-table-cell> |
| 204 | + <md-table-cell><code>Number</code></md-table-cell> |
| 205 | + <md-table-cell>Sets the maxlength and enable the text counter.</md-table-cell> |
| 206 | + </md-table-row> |
| 207 | + </md-table-body> |
| 208 | + </md-table> |
| 209 | + |
| 210 | + <md-table slot="events"> |
| 211 | + <md-table-header> |
| 212 | + <md-table-row> |
| 213 | + <md-table-head>Name</md-table-head> |
| 214 | + <md-table-head>Value</md-table-head> |
| 215 | + <md-table-head>Description</md-table-head> |
| 216 | + </md-table-row> |
| 217 | + </md-table-header> |
| 218 | + |
| 219 | + <md-table-body> |
| 220 | + <md-table-row> |
| 221 | + <md-table-cell>change</md-table-cell> |
| 222 | + <md-table-cell>The <code>String</code> selected</md-table-cell> |
| 223 | + <md-table-cell>Triggered when the user selects an item from the autocomplete list</md-table-cell> |
| 224 | + </md-table-row> |
| 225 | + <md-table-row> |
| 226 | + <md-table-cell>input</md-table-cell> |
| 227 | + <md-table-cell>The <code>String</code> selected</md-table-cell> |
| 228 | + <md-table-cell>Triggered when the user selects an item from the autocomplete list</md-table-cell> |
| 229 | + </md-table-row> |
| 230 | + <md-table-row> |
| 231 | + <md-table-cell>selected</md-table-cell> |
| 232 | + <md-table-cell>Emits the <code>Object</code> as well as the <code>String</code> selected.</md-table-cell> |
| 233 | + <md-table-cell>Triggered when the user selects an item from the autocomplete list</md-table-cell> |
| 234 | + </md-table-row> |
109 | 235 | </md-table-body>
|
110 | 236 | </md-table>
|
111 | 237 | </api-table>
|
|
156 | 282 | <md-table-cell><code>Number</code></md-table-cell>
|
157 | 283 | <md-table-cell>Sets the maxlength and enable the text counter.</md-table-cell>
|
158 | 284 | </md-table-row>
|
| 285 | + |
| 286 | + <md-table-row> |
| 287 | + <md-table-cell>readonly</md-table-cell> |
| 288 | + <md-table-cell><code>Boolean</code></md-table-cell> |
| 289 | + <md-table-cell>Sets the component to read only mode.</md-table-cell> |
| 290 | + </md-table-row> |
159 | 291 | </md-table-body>
|
160 | 292 | </md-table>
|
161 | 293 | </api-table>
|
|
169 | 301 | <label>Initial value</label>
|
170 | 302 | <md-input v-model="initialValue"></md-input>
|
171 | 303 | </md-input-container>
|
| 304 | + |
| 305 | + <md-input-container> |
| 306 | + <label>Initial value (read only)</label> |
| 307 | + <md-input v-model="initialValue" readonly></md-input> |
| 308 | + </md-input-container> |
| 309 | + |
| 310 | + <md-input-container> |
| 311 | + <label>Autocomplete (with fetch)</label> |
| 312 | + <md-autocomplete v-model="autocompleteValue" :fetch="fetchAutocomplete"></md-autocomplete> |
| 313 | + </md-input-container> |
172 | 314 |
|
173 | 315 | <md-input-container>
|
174 | 316 | <label>With label</label>
|
|
210 | 352 | <md-input v-model="initialValue"></md-input>
|
211 | 353 | </md-input-container>
|
212 | 354 |
|
| 355 | + <md-input-container> |
| 356 | + <label>Autocomplete (with fetch)</label> |
| 357 | + <md-input v-model="autocompleteValue" :fetch="fetchFunction"></md-input> |
| 358 | + </md-input-container> |
| 359 | + |
213 | 360 | <md-input-container>
|
214 | 361 | <label>With label</label>
|
215 | 362 | <md-input placeholder="My nice placeholder"></md-input>
|
|
248 | 395 | return {
|
249 | 396 | initialValue: 'My initial value'
|
250 | 397 | };
|
251 |
| - } |
| 398 | + }, |
| 399 | + methods: { |
| 400 | + fetchFunction(param) { |
| 401 | + // param = { queryParam: query } |
| 402 | + |
| 403 | + // 'fetchAutocomplete' should return a Promise. |
| 404 | + |
| 405 | + // md-autocomplete will call fetchAutocomplete and pass |
| 406 | + // 'param' as an argument. |
| 407 | + // the 'param' is composed by a query param and |
| 408 | + // a query. |
| 409 | + }, |
| 410 | + }, |
252 | 411 | };
|
253 | 412 | </code-block>
|
254 | 413 | </div>
|
|
478 | 637 | export default {
|
479 | 638 | data() {
|
480 | 639 | return {
|
481 |
| - initialValue: 'My initial value' |
| 640 | + autocompleteValue: '', |
| 641 | + initialValue: 'My initial value', |
| 642 | + listAutocomplete: [ |
| 643 | + {name: 'oi'}, |
| 644 | + {name: 'hello'}, |
| 645 | + {name: 'salut'} |
| 646 | + ] |
482 | 647 | };
|
| 648 | + }, |
| 649 | + methods: { |
| 650 | + fetchAutocomplete(param) { |
| 651 | + const myInit = { |
| 652 | + method: 'GET', |
| 653 | + headers: new Headers(), |
| 654 | + mode: 'cors', |
| 655 | + cache: 'default' |
| 656 | + }; |
| 657 | + const url = 'https://typeahead-js-twitter-api-proxy.herokuapp.com/demo/search'; |
| 658 | + const queryParam = Object.keys(param)[0]; |
| 659 | + const queryValue = param[queryParam]; |
| 660 | + const queryUrl = `${url}?${queryParam}=${queryValue}`; |
| 661 | +
|
| 662 | + return window.fetch(queryUrl, myInit) |
| 663 | + .then((res) => res.json()); |
| 664 | + }, |
| 665 | + filterList(list, query) { |
| 666 | + return list.filter((el) => el.name.indexOf(query) !== -1); |
| 667 | + } |
483 | 668 | }
|
484 | 669 | };
|
485 | 670 | </script>
|
0 commit comments