A Pen by Fabian Chinchilla on CodePen.
Created
July 18, 2018 10:14
-
-
Save phoebebright/b309b990af3a29be9c30793eab91b79d to your computer and use it in GitHub Desktop.
Materialize AutoComplete with id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
<div class="col s12"> | |
<div class="row"> | |
<div class="input-field col s13"> | |
<i class="material-icons prefix">textsms</i> | |
<input type="text" id="autocomplete" class="autocomplete" > | |
<label for="autocomplete">Autocomplete</label> | |
</div> | |
</div> | |
</div> | |
</div> | |
ID: <p id="key"></p> | |
<button class="btn" onclick="getId()">Get</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
$('.modal').modal(); | |
$('select').material_select(); | |
$('input.autocomplete').autocomplete2({ | |
data: [ | |
{id:1,text:'Apple',img:'http://placehold.it/250x250'}, | |
{id:2,text:'Microsoft',img:'http://placehold.it/250x250'}, | |
{id:3,text:'Google',img:'http://placehold.it/250x250'}, | |
] | |
}); | |
}); | |
function getId() { | |
alert($('#autocomplete').data('id')); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://codepen.io/arg3ni5/pen/VPQZwe"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.0/css/materialize.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment