Restore the ability to manually typc a value in select boxes with data-tags=true including add ticket watcher

This commit is contained in:
johnnyq
2026-10-01 15:11:58 -04:00
parent 01eceacdca
commit c3018b7584
5 changed files with 22 additions and 4 deletions

View File

@@ -288,7 +288,7 @@ ob_start();
<label>Additional Assets</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
<select class="form-select select2" name="additional_assets[]" data-tags="true" data-placeholder="- Select Additional Assets -" multiple>
<select class="form-select select2" name="additional_assets[]" data-placeholder="- Select Additional Assets -" multiple>
<option value=""></option>
<?php

View File

@@ -268,7 +268,7 @@ ob_start();
<label>Additional Assets</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
<select class="form-select select2" name="additional_assets[]" data-tags="true" data-placeholder="- Select Additional Assets -" multiple>
<select class="form-select select2" name="additional_assets[]" data-placeholder="- Select Additional Assets -" multiple>
<option value=""></option>
<?php

View File

@@ -67,7 +67,7 @@ ob_start();
<label>Additional Assets</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
<select class="form-select select2" name="additional_assets[]" data-tags="true" data-placeholder="- Select Additional Assets -" multiple>
<select class="form-select select2" name="additional_assets[]" data-placeholder="- Select Additional Assets -" multiple>
<option value=""></option>
<?php

View File

@@ -95,6 +95,10 @@ if (isset($_POST['add_ticket'])) {
// Add Watchers
if (isset($_POST['watchers'])) {
foreach ($_POST['watchers'] as $watcher) {
// Watchers is free-entry, so anything can arrive here - same check add_ticket_watcher makes
if (!filter_var($watcher, FILTER_VALIDATE_EMAIL)) {
continue;
}
$watcher_email = escapeSql($watcher);
mysqli_query($mysqli, "INSERT INTO ticket_watchers SET watcher_email = '$watcher_email', watcher_ticket_id = $ticket_id");
}

View File

@@ -61,8 +61,22 @@ function initTomSelect(el, options) {
if (el.tagName !== 'SELECT' && el.tagName !== 'INPUT') {
return null;
}
/*
* data-tags="true" is the select2 attribute for "the user can type a value
* that is not in the list". select2 read data-* attributes as options on
* its own, so the old bare $('.select2').select2() honoured it with no
* code; Tom Select does not, and every data-tags field quietly became a
* pick-from-list-only control in the migration (ticket watchers, trip
* destination, client referral, invoice scope, default start page).
*
* createOnBlur commits whatever is typed when focus leaves the control, so
* typing an address and clicking the modal's submit button posts it,
* rather than posting the empty value because Enter was never pressed.
*/
var tags = el.getAttribute('data-tags') === 'true';
var settings = Object.assign({
create: false,
create: tags,
createOnBlur: tags,
allowEmptyOption: true,
plugins: el.multiple ? ['remove_button'] : [],
placeholder: el.getAttribute('data-placeholder') || undefined