I've been attempting to extract the tag of a deleted chip from the div
within the Materialize chips class, but I'm hitting roadblocks.
My failed attempts so far:
$('.chips').on('chip.delete', function(e, chip){
console.log(chip);
console.log(e);
console.log(chip.tag);
});
None of the above code is yielding results.
Even when I simply use console.log(chip)
, I encounter an undefined error in the JavaScript console. The function does trigger upon deleting the chip, however, I cannot access the value of the tag of the deleted chip. My aim is to store this tag value in a variable.
I am dynamically creating chips based on Materialize date selection:
$('#pm_date').change(function () {
var chipvalue = $(this).val();
if (chipvalue !== "") {
// verifying if the tag already exists
if ($("#date_chip_select:contains(" + chipvalue + ")").length > 0) {
alert('Date already selected');
} else {
var appendstring = "<div class='chip' id='date_chip_child_" + chip_id + "'>" + chipvalue + "<i class='material-icons close'>close</i></div>";
}
}
});
Here's the fiddle link for further reference: https://jsfiddle.net/hq22mne4/1/