xxxxxxxxxx
1
<div class="md-form">
2
<input type="search" id="form-autocomplete" class="form-control mdb-autocomplete">
3
<button class="mdb-autocomplete-clear">
4
<svg fill="#000000" height="24" viewBox="0 0 24 24" width="24" xmlns="https://www.w3.org/2000/svg">
5
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" />
6
<path d="M0 0h24v24H0z" fill="none" />
7
</svg>
8
</button>
9
<label for="form-autocomplete" class="active">What is your favorite US state?</label>
10
</div>
11
12
<!-- This buttons changes the list of predefined values -->
13
<button type="button" class="btn btn-primary addBlabla">Add Blabla</button>
1
1
xxxxxxxxxx
1
var states = [
2
"Alabama",
3
"Alaska",
4
"Arizona",
5
"Arkansas",
6
"California",
7
"Colorado",
8
"Connecticut",
9
"Delaware",
10
"Florida",
11
"Georgia",
12
"Hawaii",
13
"Idaho",
14
"Illnois",
15
"Indiana",
16
"Iowa",
17
"Kansas",
18
"Kentucky",
19
"Louisiana",
20
"Maine",
21
"Maryland",
22
"Massachusetts",
23
"Michigan",
24
"Minnesota",
25
"Mississippi",
26
"Missouri",
27
"Montana",
28
"Nebraska",
29
"Nevada",
30
"New Hampshire",
31
"New Jersey",
32
"New Mexico",
33
"New York",
34
"North Carolina",
35
"North Dakota",
36
"Ohio",
37
"Oklahoma",
38
"Oregon",
39
"Pennsylvania",
40
"Rhode Island",
41
"South Carolina",
42
"South Dakota",
43
"Tennessee",
44
"Texas",
45
"Utah",
46
"Vermont",
47
"Virginia",
48
"Washington",
49
"West Virginia",
50
"Wisconsin",
51
"Wyoming"
52
];
53
54
$('#form-autocomplete').mdb_autocomplete({
55
data: states
56
});
57
58
$('.addBlabla').click(function(){
59
states.length = 0; /* Reset the array */
60
states.push('Blabla'); /* Add this value */
61
});
62
63
$('#form-autocomplete').change(function() {
64
console.log('Executed on field exit and changed');
65
});
66
67
$('#form-autocomplete').bind('input', function(){
68
if ($(this).val().length<2) return; /* Do not run on short text */
69
console.log('Executed bind');
70
states.length = 0; /* Reset the array */
71
states.push('Mexico'); /* Add this value */
72
states.push('Moroko'); /* Add this value */
73
});
74
75
Console errors: 0