Skip to content

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

Add editable field labels to custom fields (#1404)

Leendert de Borst1c43caaf57cf
diff --git a/apps/server/AliasVault.Client/Main/Components/Forms/EditableFieldLabel.razor b/apps/server/AliasVault.Client/Main/Components/Forms/EditableFieldLabel.razor
new file mode 100644
index 000000000..1e631b75a
--- /dev/null
+++ b/apps/server/AliasVault.Client/Main/Components/Forms/EditableFieldLabel.razor
@@ -0,0 +1,126 @@
+@using Microsoft.Extensions.Localization
+
+@inject IStringLocalizerFactory LocalizerFactory
+
+@if (IsEditing)
+{
+ <div class="flex items-center gap-2 mb-2">
+ <input type="text"
+ @bind="EditValue"
+ @bind:event="oninput"
+ @onkeydown="HandleKeyDown"
+ @onblur="HandleSave"
+ class="flex-1 px-2 py-1 text-sm font-medium text-gray-900 dark:text-white border border-primary-500 rounded focus:outline-none focus:ring-1 focus:ring-primary-500 dark:bg-gray-700 dark:border-primary-400"
+ placeholder="@Localizer["FieldLabelPlaceholder"]"
+ @ref="EditInputRef" />
+ <button type="button"
+ @onclick="HandleSave"
+ @onclick:preventDefault="true"
+ class="text-green-600 dark:text-green-400 hover:text-green-700 dark:hover:text-green-300 text-xs px-2 py-1">
+ ✓
+ </button>
+ <button type="button"
+ @onclick="HandleCancel"
+ @onclick:preventDefault="true"
+ class="text-gray-600 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 text-xs px-2 py-1">
+ ✕
+ </button>
+ </div>
+}
+else
+{
+ <div class="flex items-center gap-2 mb-2">
+ <label for="@HtmlFor" class="text-sm font-medium text-gray-900 dark:text-white">@Label</label>
+ <button type="button"
+ @onclick="StartEditing"
+ @onclick:preventDefault="true"
+ class="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 text-xs"
+ title="@Localizer["EditLabel"]">
+ <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" />
+ </svg>
+ </button>
+ @if (OnDelete.HasDelegate)
+ {
+ <button type="button"
+ @onclick="HandleDelete"
+ @onclick:preventDefault="true"
+ class="text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 text-xs"
+ title="@Localizer["DeleteField"]">
+ <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
+ </svg>
+ </button>
+ }
+ </div>
+}
+
+@code {
+ private IStringLocalizer Localizer => LocalizerFactory.Create("Components.Main.Forms.EditableFieldLabel", "AliasVault.Client");
+
+ /// <summary>
+ /// Gets or sets the HTML for attribute to associate with the input.
+ /// </summary>
+ [Parameter]
+ public string HtmlFor { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the current label text.
+ /// </summary>
+ [Parameter]
+ public string Label { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the callback when the label changes.
+ /// </summary>
+ [Parameter]
+ public EventCallback<string> LabelChanged { get; set; }
+
+ /// <summary>
+ /// Gets or sets the callback when the delete button is clicked.
+ /// </summary>
+ [Parameter]
+ public EventCallback OnDelete { get; set; }
+
+ private bool IsEditing { get; set; }
+ private string EditValue { get; set; } = string.Empty;
+ private ElementReference EditInputRef;
+
+ private void StartEditing()
+ {
+ EditValue = Label;
+ IsEditing = true;
+ }
+
+ private async Task HandleSave()
+ {
+ if (!string.IsNullOrWhiteSpace(EditValue))
+ {
+ await LabelChanged.InvokeAsync(EditValue.Trim());
+ }
+ IsEditing = false;
+ }
+
+ private void HandleCancel()
+ {
+ EditValue = Label;
+ IsEditing = false;
+ }
+
+ private async Task HandleKeyDown(KeyboardEventArgs e)
+ {
+ if (e.Key == "Enter")
+ {
+ await HandleSave();
+ }
+ else if (e.Key == "Escape")
+ {
+ HandleCancel();
+ }
+ }
+
+ private async Task HandleDelete()
+ {
+ await OnDelete.InvokeAsync();
+ }
+}
diff --git a/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs b/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs
index bd2fc6136..036b13d80 100644
--- a/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs
+++ b/apps/server/AliasVault.Client/Main/Models/ItemEdit.cs
@@ -346,8 +346,8 @@ public sealed class ItemEdit
}
else
{
- // Existing custom field - update value
- item.FieldValues.Add(new FieldValue
+ // Existing custom field - update value and include FieldDefinition with updated label
+ var fieldValue = new FieldValue
{
Id = customField.Id != Guid.Empty ? customField.Id : Guid.NewGuid(),
ItemId = item.Id,
@@ -355,7 +355,24 @@ public sealed class ItemEdit
FieldKey = null,
Value = customField.Value,
Weight = 0,
- });
+ };
+
+ // Include FieldDefinition with potentially updated label for update logic
+ if (customField.FieldDefinitionId != Guid.Empty)
+ {
+ fieldValue.FieldDefinition = new FieldDefinition
+ {
+ Id = customField.FieldDefinitionId,
+ Label = customField.Label,
+ FieldType = customField.FieldType,
+ IsHidden = customField.IsHidden,
+ IsMultiValue = false,
+ EnableHistory = false,
+ Weight = 0,
+ };
+ }
+
+ item.FieldValues.Add(fieldValue);
}
}
diff --git a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
index f0b862b94..c027103b2 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Items/AddEdit.razor
@@ -340,25 +340,28 @@ else
<div class="grid gap-6">
@foreach (var customField in Obj.CustomFields)
{
- <div class="col-span-6 relative">
+ <div class="col-span-6">
+ <EditableFieldLabel
+ HtmlFor="@($"custom-{customField.TempId ?? customField.Id.ToString()}")"
+ Label="@customField.Label"
+ LabelChanged="@((newLabel) => UpdateCustomFieldLabel(customField, newLabel))"
+ OnDelete="@(() => RemoveCustomField(customField))" />
@if (customField.FieldType == "TextArea")
{
- <EditFormRow Type="textarea" Id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" Label="@customField.Label" @bind-Value="customField.Value"></EditFormRow>
+ <div class="relative">
+ <textarea id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" style="height: 200px;" class="outline-0 shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white" @bind="customField.Value"></textarea>
+ </div>
}
else if (customField.IsHidden || customField.FieldType == "Hidden" || customField.FieldType == "Password")
{
- <EditPasswordFormRow Id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" Label="@customField.Label" @bind-Value="customField.Value" ShowPassword="false"></EditPasswordFormRow>
+ <EditPasswordFormRow Id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" Label="" @bind-Value="customField.Value" ShowPassword="false"></EditPasswordFormRow>
}
else
{
- <EditFormRow Id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" Label="@customField.Label" @bind-Value="customField.Value"></EditFormRow>
+ <div class="relative">
+ <input type="text" id="@($"custom-{customField.TempId ?? customField.Id.ToString()}")" autocomplete="off" class="outline-0 shadow-sm bg-gray-50 border border-gray-300 text-gray-900 sm:text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white" @bind="customField.Value" autocapitalize="off" autocorrect="off">
+ </div>
}
- <button type="button" @onclick="() => RemoveCustomField(customField)" @onclick:preventDefault="true"
- class="absolute top-0 right-0 text-gray-400 hover:text-red-500 transition-colors" title="@Localizer["RemoveField"]">
- <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
- </svg>
- </button>
</div>
}
</div>
@@ -636,6 +639,15 @@ else
StateHasChanged();
}
+ /// <summary>
+ /// Updates the label of a custom field.
+ /// </summary>
+ private void UpdateCustomFieldLabel(CustomFieldEdit field, string newLabel)
+ {
+ field.Label = newLabel;
+ StateHasChanged();
+ }
+
/// <summary>
/// Handles item type change.
/// </summary>
diff --git a/apps/server/AliasVault.Client/Resources/Components/Main/Forms/EditableFieldLabel.en.resx b/apps/server/AliasVault.Client/Resources/Components/Main/Forms/EditableFieldLabel.en.resx
new file mode 100644
index 000000000..a1b5a3b2a
--- /dev/null
+++ b/apps/server/AliasVault.Client/Resources/Components/Main/Forms/EditableFieldLabel.en.resx
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+
+ <data name="FieldLabelPlaceholder">
+ <value>Field label</value>
+ <comment>Placeholder text for field label input</comment>
+ </data>
+ <data name="EditLabel">
+ <value>Edit label</value>
+ <comment>Tooltip for edit label button</comment>
+ </data>
+ <data name="DeleteField">
+ <value>Delete field</value>
+ <comment>Tooltip for delete field button</comment>
+ </data>
+</root>
diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.cs
index 5dc02bf0b..9c047aa84 100644
--- a/apps/server/AliasVault.Client/Services/ItemService.cs
+++ b/apps/server/AliasVault.Client/Services/ItemService.cs
@@ -308,6 +308,7 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
var item = await context.Items
.Include(x => x.FieldValues.Where(fv => !fv.IsDeleted))
+ .ThenInclude(fv => fv.FieldDefinition)
.Include(x => x.Logo)
.Include(x => x.Attachments.Where(a => !a.IsDeleted))
.Include(x => x.TotpCodes.Where(t => !t.IsDeleted))
@@ -330,6 +331,7 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
var items = await context.Items
.Include(x => x.FieldValues.Where(fv => !fv.IsDeleted))
+ .ThenInclude(fv => fv.FieldDefinition)
.Include(x => x.Logo)
.Include(x => x.Attachments.Where(a => !a.IsDeleted))
.Include(x => x.TotpCodes.Where(t => !t.IsDeleted))
@@ -656,13 +658,23 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
if (existingByFieldDefId.TryGetValue(newField.FieldDefinitionId.Value, out var existingField))
{
- // Update existing
+ // Update existing field value
if (existingField.Value != newField.Value || existingField.Weight != newField.Weight)
{
existingField.Value = newField.Value;
existingField.Weight = newField.Weight;
existingField.UpdatedAt = updateDateTime;
}
+
+ // Also update the FieldDefinition label if it has changed
+ if (newField.FieldDefinition != null && existingField.FieldDefinition != null)
+ {
+ if (existingField.FieldDefinition.Label != newField.FieldDefinition.Label)
+ {
+ existingField.FieldDefinition.Label = newField.FieldDefinition.Label;
+ existingField.FieldDefinition.UpdatedAt = updateDateTime;
+ }
+ }
}
else
{
diff --git a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
index b1488b911..851f44ab9 100644
--- a/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
+++ b/apps/server/AliasVault.Client/wwwroot/css/tailwind.css
@@ -2891,6 +2891,16 @@ video {
color: rgb(239 68 68 / var(--tw-text-opacity));
}
+.hover\:text-gray-600:hover {
+ --tw-text-opacity: 1;
+ color: rgb(75 85 99 / var(--tw-text-opacity));
+}
+
+.hover\:text-green-700:hover {
+ --tw-text-opacity: 1;
+ color: rgb(21 128 61 / var(--tw-text-opacity));
+}
+
.hover\:underline:hover {
text-decoration-line: underline;
}
@@ -2936,6 +2946,12 @@ video {
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}
+.focus\:ring-1:focus {
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
+}
+
.focus\:ring-inset:focus {
--tw-ring-inset: inset;
}
@@ -3145,6 +3161,11 @@ video {
border-color: rgb(133 77 14 / var(--tw-border-opacity));
}
+.dark\:border-primary-400:is(.dark *) {
+ --tw-border-opacity: 1;
+ border-color: rgb(246 167 82 / var(--tw-border-opacity));
+}
+
.dark\:bg-amber-800\/30:is(.dark *) {
background-color: rgb(146 64 14 / 0.3);
}
@@ -3703,6 +3724,11 @@ video {
color: rgb(255 255 255 / var(--tw-text-opacity));
}
+.dark\:hover\:text-green-300:hover:is(.dark *) {
+ --tw-text-opacity: 1;
+ color: rgb(134 239 172 / var(--tw-text-opacity));
+}
+
.dark\:hover\:file\:bg-primary-800\/60:is(.dark *)::file-selector-button:hover {
background-color: rgb(154 93 38 / 0.6);
}