0
I have a form with several fields, one of them I use Tagsmanager to insert tags (registered clients), now when I send this form I need to save the ID’s of these registered clients in the same field, separated by comma.
I tried using the Hidden field and also the parameter: Hiddentaglistid, and it didn’t work.
Documentation: https://maxfavilli.com/jquery-tag-manager
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’t access either "label" or "value". The item parameter returns only the name that is in the tag and item.value gives error. How to add this information in the tag?
I tried to adapt the Mahdi-Farhani cometarium in the documentation but I couldn’t either. Follow the link:
github.com/max-Favilli/tagmanager/issues/7
any tips? I have tried several ways and failed.
– Danimar Varisa