From 5ee22cd407d836e195e3ea0d897dd015fd2f208e Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 28 May 2025 13:01:41 +0300 Subject: [PATCH] Add social link controls using html template --- app/assets/javascripts/user.js | 22 ++++++---------------- app/views/profiles/show.html.erb | 8 ++++++++ config/locales/en.yml | 2 -- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/user.js b/app/assets/javascripts/user.js index f9de24bc2..5d96ccf5f 100644 --- a/app/assets/javascripts/user.js +++ b/app/assets/javascripts/user.js @@ -14,22 +14,12 @@ $(function () { if ($("#social_links").length) { $("#add-social-link").click(function () { const newIndex = -Date.now(); - const socialLinkForm = $(` - - `); - - socialLinkForm.find("button").click(function () { - $(this).parent().remove(); - }); - - $("#social_links").append(socialLinkForm); - - socialLinkForm.find("input").trigger("focus"); + + $("#social_links template").contents().clone().appendTo("#social_links") + .find("input").attr("name", `user[social_links_attributes][${newIndex}][url]`).trigger("focus") + .end().find("button").on("click", function () { + $(this).parent().remove(); + }); }); $(".social_link_destroy input[type='checkbox']").change(function () { diff --git a/app/views/profiles/show.html.erb b/app/views/profiles/show.html.erb index d09242024..e3e093e86 100644 --- a/app/views/profiles/show.html.erb +++ b/app/views/profiles/show.html.erb @@ -15,6 +15,14 @@ <%= f.label t(".social_links.title"), :class => "form-label" %>