Ensure a min of 2 metadata input rows on profile edit form (#297)

pull/298/head
Michael Manfre 2022-12-27 19:45:51 -05:00 zatwierdzone przez GitHub
rodzic c6c3914cc7
commit efe6864418
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 19 dodań i 7 usunięć

Wyświetl plik

@ -42,11 +42,17 @@
set two to the first <input.{{ field.name }}-{{ name_two }}/> 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
"></span>
<div class="option">
<span class="option-field">
<button class="fa-solid fa-add" _="on click {{ field.name }}.addEmptyField() then halt"></button>
<button class="fa-solid fa-add" title="Add Row" _="on click {{ field.name }}.addEmptyField() then halt"></button>
</span>
</div>
@ -58,7 +64,7 @@
<input type=text class="{{ field.name }}-{{ name_two }}" name="{{ field.name }}_{{ name_two }}" value="">
</span>
<div class="right">
<button class="fa-solid fa-trash delete"
<button class="fa-solid fa-trash delete" title="Delete Row"
_="on click remove (closest parent .option)
then {{ field.name }}.collect{{ field.name|title }}Fields()
then halt" />

Wyświetl plik

@ -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)