diff --git a/templates/forms/_json_name_value_list.html b/templates/forms/_json_name_value_list.html
index 65a7262..a2b0459 100644
--- a/templates/forms/_json_name_value_list.html
+++ b/templates/forms/_json_name_value_list.html
@@ -42,11 +42,17 @@
set two to the first in f then
set two@value to item.{{ name_two }}
end
+ get the (@data-min-empty of #id_{{ field.name }})
+ set min_empty to it
+ if items.length < min_empty then
+ repeat (min_empty - items.length) times
+ call {{ field.name }}.addEmptyField()
+ end
">
-
+
@@ -58,7 +64,7 @@
-
diff --git a/users/views/settings/profile.py b/users/views/settings/profile.py
index 0e9ebf4..110fb02 100644
--- a/users/views/settings/profile.py
+++ b/users/views/settings/profile.py
@@ -50,10 +50,18 @@ class ProfilePage(FormView):
metadata = forms.JSONField(
label="Profile Metadata Fields",
help_text="These values will appear on your profile below your Bio",
- widget=forms.HiddenInput,
+ widget=forms.HiddenInput(attrs={"data-min-empty": 2}),
required=False,
)
+ def clean_metadata(self):
+ metadata = self.cleaned_data["metadata"]
+ if metadata:
+ metadata = [x for x in metadata if x["name"] and x["value"]]
+ if not metadata:
+ return None
+ return metadata
+
def get_initial(self):
identity = self.request.identity
return {
@@ -63,7 +71,7 @@ class ProfilePage(FormView):
"image": identity.image and identity.image.url,
"discoverable": identity.discoverable,
"visible_follows": identity.config_identity.visible_follows,
- "metadata": identity.metadata,
+ "metadata": identity.metadata or [],
}
def form_valid(self, form):
@@ -85,9 +93,7 @@ class ProfilePage(FormView):
image.name,
resize_image(image, size=(1500, 500)),
)
- metadata = form.cleaned_data.get("metadata")
- if metadata:
- identity.metadata = metadata
+ identity.metadata = form.cleaned_data.get("metadata")
identity.save()
identity.transition_perform(IdentityStates.edited)