I have a form with several fields, one of them I use TagsManager to insert tags (clients registered), now when I send this form I need to save the ID's of these clients registered in the same field, separated by commas.
I have tried to use the Hidden field as well as the parameter: HiddenTagListId, and it did not work.
Documentation: link
HTML:
<div class="form-group col-xs-6">
<label for="parte_interessada">Parte interessada</label>
<input type="text" class="typeahead cliente form-control" id="cliente" name="cliente">
<div class="tags_cliente"></div>
JAVASCRIPT
<script>
$(document).ready(function() {
var tagApi = $(".cliente").tagsManager({
tagsContainer: '.tags_cliente',
});
var cliente= new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "busca-cliente.php?query=%QUERY",
wildcard: "%QUERY"
}
});
$('#cliente').typeahead(null, {
name: 'cliente',
display: 'label',
source: cliente,
afterSelect: function(item) {
tagApi.tagsManager("pushTag", item);
},
templates: {
header: '<strong> Clientes encontrados:</strong>',
empty: [
' Não foram encontrados resultados com os termos informados!'
]
},
})
);
The autocomplete search returns:
while($row = $result->fetch_assoc()){
$data[] = array(
'label' => $row['nome'],
'value' => $row['id'],
);
}
echo json_encode($data);
When I use the "typeahead: selected" function, I can access "label" or "value".
.on('typeahead:selected', function(event, data){
$('#id_cliente').val(data.value);
});
However, using the "tm: pushed" and "tm: spliced" functions you suggested, I can not access either "label" or "value". The item parameter returns only the name that is in the tag and item.value gives error. How do I add this information to the tag?
I tried to adapt Mahdi-Farhani's commentary in the documentation but I could not. Follow the link:
github.com/max-favilli/tagmanager/issues/7