Ich habe eine Autovervollständigung auf einem Formular vorgenommen, wo es möglich ist, eine neue Zeile hinzuzufügen.Zeile anfügen Autocomplete hinzufügen jQuery
Meine automatische Vervollständigung sperrt jedoch nur das erste Element.
Können Sie mir helfen, die automatische Vervollständigung für die Arbeit an angehängten Zeilen zu bekommen.
jsFiddle: https://jsfiddle.net/r65x9aj0/3/
Javascript:
var globalNewIndex = 0;
var availableAttributes = [
"account_address",
"account_address_city",
"account_address_country",
"account_address_state",
"account_address_street1",
"account_address_street2",
"account_address_zip",
"account_email",
"account_login",
"account_name",
"account_number",
"account_telephone"
];
$(document).ready(function() {
$('#fixed_name_'+globalNewIndex).autocomplete({
source: availableAttributes
});
$("#add").click(function() {
var newIndex = globalNewIndex+1;
var changeIds = function(i, val) {
return val.replace(globalNewIndex,newIndex);
}
$('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last');
$('#mytable tbody>tr:last input').attr('name', changeIds).attr('id', changeIds);
globalNewIndex++;
$('#fixed_name_'+globalNewIndex).autocomplete({
source: availableAttributes
});
$('#mytable tbody>tr:last .emptythis').val('');
$("#mytable tbody>tr:last").each(function() {this.reset();});
return false;
});
});
HTML:
<table id="mytable" class="table table-hover">
<thead>
<tr style="font-weight: bold">
<td>Item number
</td>
<td>Price EUR
</td>
</tr>
</thead>
<tbody>
<tr class="person">
<td>
<input type="text" name="fixed_name[0]" id="fixed_name_0" class="form-control emptythis" autocomplete="off" />
</td>
<td>
<input type="number" name="fixed_price[0]" id="fixed_price_0" class="form-control emptythis" autocomplete="off" />
</td>
</tr>
</tbody>
</table>
<div class="row">
<div class="col-md-3">
<button type="button" class="btn btn-success btn-block btn-lg" id="add">Add line
</button>
</div>
<div class="col-md-9">
<button type="submit" class="btn btn-primary btn-block btn-lg" id="searchinternal">Update
</button>
</div>
</div>
</form>
Dank zu arbeiten, wirkt wie ein Zauber! –