Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Tweak add custom field menu and custom field display (#1404)

Leendert de Borstcc28fd8cc2ae
diff --git a/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor b/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
index 24cf953ce..fcc36995e 100644
--- a/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
+++ b/apps/server/AliasVault.Client/Main/Components/Fields/FieldBlock.razor
@@ -41,7 +41,7 @@
</div>
break;
case "Date":
- <div class="col-span-6 sm:col-span-3">
+ <div class="@(FullWidth ? "col-span-6" : "col-span-6 sm:col-span-3")">
<CopyPasteFormRow
Id="@GetFieldId()"
Label="@GetLabel()"
@@ -50,7 +50,7 @@
break;
default:
@* Text, Email, Phone, Number - use standard copy/paste row *@
- <div class="col-span-6 sm:col-span-3">
+ <div class="@(FullWidth ? "col-span-6" : "col-span-6 sm:col-span-3")">
<CopyPasteFormRow
Id="@GetFieldId()"
Label="@GetLabel()"
@@ -71,6 +71,12 @@
[Parameter]
public required DisplayField Field { get; set; }
+ /// <summary>
+ /// Gets or sets whether the field should span full width.
+ /// </summary>
+ [Parameter]
+ public bool FullWidth { get; set; }
+
/// <summary>
/// Gets the label for the field.
/// </summary>
diff --git a/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor b/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor
index 871fc954e..ae104890f 100644
--- a/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor
+++ b/apps/server/AliasVault.Client/Main/Components/Items/AddFieldMenu.razor
@@ -1,8 +1,10 @@
@using AliasClientDb.Models
@using AliasVault.Client.Main.Components.Layout
+@using AliasVault.Client.Services.JsInterop
@using Microsoft.Extensions.Localization
@inject IStringLocalizerFactory LocalizerFactory
+@inject JsInteropService JsInteropService
<div class="relative">
<button type="button"
@@ -85,7 +87,6 @@
Title="@Localizer["AddCustomField"]"
ConfirmText="@Localizer["Add"]"
CancelText="@Localizer["Cancel"]"
- ConfirmDisabled="@string.IsNullOrWhiteSpace(CustomFieldLabel)"
ConfirmButtonClass="bg-primary-600 hover:bg-primary-500 dark:bg-primary-700 dark:hover:bg-primary-600"
MaxWidth="md"
OnClose="CloseCustomFieldModal"
@@ -102,6 +103,7 @@
@Localizer["FieldLabel"]
</label>
<input type="text"
+ id="custom-field-label-input"
@bind="CustomFieldLabel"
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm focus:outline-none focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:text-white"
placeholder="@Localizer["EnterFieldName"]" />
@@ -171,6 +173,12 @@
[Parameter]
public EventCallback<(string Label, string FieldType)> OnAddCustomField { get; set; }
+ /// <summary>
+ /// Current count of custom fields, used for auto-generating default labels.
+ /// </summary>
+ [Parameter]
+ public int CustomFieldCount { get; set; }
+
/// <summary>
/// Callback when 2FA section is added.
/// </summary>
@@ -216,12 +224,17 @@
CloseMenu();
}
- private void OpenCustomFieldModal()
+ private async Task OpenCustomFieldModal()
{
ShowCustomFieldModal = true;
- CustomFieldLabel = string.Empty;
+ // Auto-generate a default label based on existing custom field count
+ CustomFieldLabel = string.Format(Localizer["DefaultFieldLabel"].Value, CustomFieldCount + 1);
CustomFieldType = "Text";
CloseMenu();
+
+ // Wait for the modal to render, then focus and select the input text
+ await Task.Delay(50);
+ await JsInteropService.FocusAndSelectElementById("custom-field-label-input");
}
private Task CloseCustomFieldModal()
diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
index e62c9df82..39a32fbdc 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
@@ -381,6 +381,7 @@ else
Show2FA="@Show2FA"
ShowAttachments="@ShowAttachments"
HasLoginFields="@HasLoginFields()"
+ CustomFieldCount="@Obj.GetCustomFields().Count"
OnAddSystemField="AddOptionalField"
OnAddCustomField="AddCustomField"
OnAdd2FA="Add2FASection"
diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/View.razor b/apps/server/AliasVault.Client/Main/Pages/Items/View.razor
index bf397a231..fcc1441ad 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Items/View.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Items/View.razor
@@ -248,7 +248,7 @@ else
<div class="grid grid-cols-6 gap-6">
@foreach (var field in customFields)
{
- <FieldBlock Field="@field" />
+ <FieldBlock Field="@field" FullWidth="true" />
}
</div>
</form>
diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Items/AddFieldMenu.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Items/AddFieldMenu.en.resx
index 032ff4b2a..24056004b 100644
--- a/apps/server/AliasVault.Client/Resources/Components/Main/Items/AddFieldMenu.en.resx
+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Items/AddFieldMenu.en.resx
@@ -151,4 +151,10 @@
<value>Cancel</value>
<comment>Cancel button text</comment>
</data>
+
+ <!-- Default field label -->
+ <data name="DefaultFieldLabel">
+ <value>Field {0}</value>
+ <comment>Default label for custom field, {0} is the field number</comment>
+ </data>
</root>
diff --git a/apps/server/AliasVault.Client/Services/JsInterop/JsInteropService.cs b/apps/server/AliasVault.Client/Services/JsInterop/JsInteropService.cs
index b3eab6929..1684a9fca 100644
--- a/apps/server/AliasVault.Client/Services/JsInterop/JsInteropService.cs
+++ b/apps/server/AliasVault.Client/Services/JsInterop/JsInteropService.cs
@@ -103,6 +103,14 @@ public sealed class JsInteropService(IJSRuntime jsRuntime)
public async Task FocusElementById(string elementId) =>
await jsRuntime.InvokeVoidAsync("focusElement", elementId);
+ /// <summary>
+ /// Focus an element by its ID and select all its text.
+ /// </summary>
+ /// <param name="elementId">The element ID to focus and select.</param>
+ /// <returns>Task.</returns>
+ public async Task FocusAndSelectElementById(string elementId) =>
+ await jsRuntime.InvokeVoidAsync("focusAndSelectElement", elementId);
+
/// <summary>
/// Blur (defocus) an element by its ID.
/// </summary>
diff --git a/apps/server/AliasVault.Client/wwwroot/js/utilities.js b/apps/server/AliasVault.Client/wwwroot/js/utilities.js
index 45e680cac..e2d3d2905 100644
--- a/apps/server/AliasVault.Client/wwwroot/js/utilities.js
+++ b/apps/server/AliasVault.Client/wwwroot/js/utilities.js
@@ -219,6 +219,16 @@ window.focusElement = (elementId) => {
}
};
+window.focusAndSelectElement = (elementId) => {
+ const element = document.getElementById(elementId);
+ if (element) {
+ element.focus();
+ if (element.select) {
+ element.select();
+ }
+ }
+};
+
window.blurElement = (elementId) => {
const element = document.getElementById(elementId);
if (element) {