From 08697e0b1bbdc054f4a0e324c48637bb4e777717 Mon Sep 17 00:00:00 2001 From: Robert Haken Date: Wed, 11 Dec 2024 12:03:21 +0100 Subject: [PATCH] fix #964 [HxAutosuggest] ReferenceError: dropdown is not defined --- .../wwwroot/HxAutosuggest.js | 5 ++--- .../DemoData/DemoDataService.cs | 14 ++++++++++++++ .../DemoData/IDemoDataService.cs | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Havit.Blazor.Components.Web.Bootstrap/wwwroot/HxAutosuggest.js b/Havit.Blazor.Components.Web.Bootstrap/wwwroot/HxAutosuggest.js index f13d84781..ee05f84fc 100644 --- a/Havit.Blazor.Components.Web.Bootstrap/wwwroot/HxAutosuggest.js +++ b/Havit.Blazor.Components.Web.Bootstrap/wwwroot/HxAutosuggest.js @@ -64,11 +64,10 @@ export function destroy(inputElement) { const d = bootstrap.Dropdown.getInstance(inputElement); if (d) { - d.hide(); - inputElement.addEventListener('hidden.bs.dropdown', event => { - dropdown.dispose() + d.dispose() }) + d.hide(); } } diff --git a/Havit.Blazor.Documentation/DemoData/DemoDataService.cs b/Havit.Blazor.Documentation/DemoData/DemoDataService.cs index e536da8c2..23c555d9f 100644 --- a/Havit.Blazor.Documentation/DemoData/DemoDataService.cs +++ b/Havit.Blazor.Documentation/DemoData/DemoDataService.cs @@ -173,4 +173,18 @@ public async Task UpdateEmployeeAsync(EmployeeDto employee, CancellationToken ca existingEmployee.Position = employee.Position; existingEmployee.Location = employee.Location; } + + public async Task CreateNewEmployeeAsync(EmployeeDto employee, CancellationToken cancellationToken = default) + { + _logger.LogInformation($"DemoDataService.CreateNewEmployeeAsync() called."); + Contract.Requires(employee.Id == 0, "Employee ID must be 0."); + + // simulate server call + await Task.Delay(140, cancellationToken); + + var newEmployee = employee with { Id = _employees.Max(e => e.Id) + 1 }; + _employees.Add(newEmployee); + + return newEmployee.Id; + } } diff --git a/Havit.Blazor.Documentation/DemoData/IDemoDataService.cs b/Havit.Blazor.Documentation/DemoData/IDemoDataService.cs index d6f99dbf9..96504c163 100644 --- a/Havit.Blazor.Documentation/DemoData/IDemoDataService.cs +++ b/Havit.Blazor.Documentation/DemoData/IDemoDataService.cs @@ -16,4 +16,5 @@ public interface IDemoDataService Task UpdateEmployeeAsync(EmployeeDto employee, CancellationToken cancellationToken = default); Task DeleteEmployeeAsync(int employeeId, CancellationToken cancellationToken = default); + Task CreateNewEmployeeAsync(EmployeeDto employee, CancellationToken cancellationToken = default); } \ No newline at end of file