Naomi-lifelab Posted June 21, 2022 Share Posted June 21, 2022 (edited) Site URL: https://lifelab.world/de/spaces Hello Squarespace team, May I please ask for help in checking the code below? I am trying to translate a form field using this code, which I have been using since last year which was also provided here on the forum as well. I am unsure why it is not working on this specific button. (lower part of the page) Everything seems to be working on other types of German forms that I edited with the exact details below. I usually duplicate a page then just change some texts, but the forms are usually the same, the only differences are the block IDs for the codes. I added this on the Settings > Advanced > Code Injection > Footer <script> if (document.querySelector("#block-2cd3c3f72a1a11967dd0")) { document.querySelector('.field.first-name .caption .caption-text').innerText = 'Vorname'; document.querySelector('.field.last-name .caption .caption-text').innerText = 'Nachname'; document.querySelector('.field.address1 .caption .caption-text').innerText = 'Company name'; document.querySelector('.field.address2 .caption .caption-text').innerText = 'Anschrift'; document.querySelector('.field.city .caption .caption-text').innerText = 'Stadt'; document.querySelector('.field.state-province .caption .caption-text').innerText = 'Bundeslandz'; document.querySelector('.field.zip .caption .caption-text').innerText = 'Postleitzahl'; document.querySelector('.field.country .caption .caption-text').innerText = 'Land'; } </script> Am I doing something wrong? Thank you in advance! Edited June 21, 2022 by Naomi-lifelab clicked enter immediately Link to comment
Naomi-lifelab Posted July 14, 2022 Author Share Posted July 14, 2022 Site URL: https://lifelab.world/search?q= Hi everyone, May I please ask for help? There seems to be a problem with the code injection lately. I have tried applying all of these on the code injection but none of them seem to work. These are the items I want to be changed which is Type to search = Zum Suchen tippen Link: https://lifelab.world/search?q= <script> $(document).ready(function() { $('body.body-de .sqs-search-page input').attr('placeholder','Zum Suchen tippen'); }); </script> The other one is a form that I am trying to translate as I press the button Bewirb dich hierLink: https://lifelab.world/de/spaces Here is the code: <script> if (document.querySelector("#block-2cd3c3f72a1a11967dd0")) { document.querySelector('.field.first-name .caption .caption-text').innerText = 'Vorname'; document.querySelector('.field.last-name .caption .caption-text').innerText = 'Nachname'; document.querySelector('.field.address1 .caption .caption-text').innerText = 'Company name'; document.querySelector('.field.address2 .caption .caption-text').innerText = 'Anschrift'; document.querySelector('.field.city .caption .caption-text').innerText = 'Stadt'; document.querySelector('.field.state-province .caption .caption-text').innerText = 'Bundeslandz'; document.querySelector('.field.zip .caption .caption-text').innerText = 'Postleitzahl'; document.querySelector('.field.country .caption .caption-text').innerText = 'Land'; } </script> I placed them all in footer. I have asked on the original threads that I made but no one has replied yet. 😞 Thank you in advance Link to comment
paul2009 Posted July 14, 2022 Share Posted July 14, 2022 24 minutes ago, Naomi-lifelab said: There seems to be a problem with the code injection lately. This isn't a problem with Code Injection on Squarespace, it's just a little problem with your code 🙂 If you take a look through your earlier code (before the code you quoted above) you'll see that you've repeated the same code twice and in doing so have declared the same constants ('translate' and 'translate1') more than once - which you cannot do! If you remove the duplicate sections, things should run more smoothly. Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥. Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links. Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional. Would you like your customers to be able to mark their favourite products in your Squarespace store? Link to comment
Naomi-lifelab Posted July 14, 2022 Author Share Posted July 14, 2022 17 minutes ago, paul2009 said: This isn't a problem with Code Injection on Squarespace, it's just a little problem with your code 🙂 If you take a look through your earlier code (before the code you quoted above) you'll see that you've repeated the same code twice and in doing so have declared the same constants ('translate' and 'translate1') more than once - which you cannot do! If you remove the duplicate sections, things should run more smoothly. Hello Paul, Thank you so much for replying. I really appreciate it. 🙏 I just wanted clarify as I am not that much of an expert. I have repeated this code 5 times with different block-ids in the footer - code injection section. So what caused the problem is me adding the code multiple time, right? Can I just add all the block IDs in one code? If so, may I please ask on how to do it? Like for example: <script> if (document.querySelector("#block-2cd3c3f72a1a11967dd0, #block-0d55eda3023d78a9c134, #block-5d0d9e64cf7cce9ec333, #block-7e4a384bb11453f45f5e, #block-b5f0f6b171bc88ba369e")) Would this be correct? The blocks at the end are the block codes that worked before. Also what about for this code? This is just a single code that I just recently added, no other one like it in the code injection section. <script> $(document).ready(function() { $('body.body-de .sqs-search-page input').attr('placeholder','Zum Suchen tippen'); }); </script> Thank you so much for your help Link to comment
paul2009 Posted July 14, 2022 Share Posted July 14, 2022 2 hours ago, Naomi-lifelab said: So what caused the problem is me adding the code multiple time, right? If you look through the scripts on the website you'll see two copies of this: const translate = { Jan: "Jän", Feb: "Feb", Mar: "März", Apr: "Apr", May: "Mai", Jun: "Juni", Jul: "Juli", Aug: "Aug", Sep: "Sept", Oct: "Okt", Nov: "Nov", Dec: "Dek" } const translate1 = { January: "Januar", February: "Februar", March: "März", April: "April", May: "Mai", June: "Juni", July: "Juli", August: "August", September: "September", October: "Oktober", November: "November", December: "Dezember" } There should only be one (and there is no benefit in having two). Once the browser finds this problem it goes 🤯 and doesn't execute any of the other code that follows 🙂 Naomi-lifelab 1 Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥. Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links. Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional. Would you like your customers to be able to mark their favourite products in your Squarespace store? Link to comment
Naomi-lifelab Posted July 19, 2022 Author Share Posted July 19, 2022 On 7/14/2022 at 11:05 PM, paul2009 said: If you look through the scripts on the website you'll see two copies of this: const translate = { Jan: "Jän", Feb: "Feb", Mar: "März", Apr: "Apr", May: "Mai", Jun: "Juni", Jul: "Juli", Aug: "Aug", Sep: "Sept", Oct: "Okt", Nov: "Nov", Dec: "Dek" } const translate1 = { January: "Januar", February: "Februar", March: "März", April: "April", May: "Mai", June: "Juni", July: "Juli", August: "August", September: "September", October: "Oktober", November: "November", December: "Dezember" } There should only be one (and there is no benefit in having two). Once the browser finds this problem it goes 🤯 and doesn't execute any of the other code that follows 🙂 Hello @paul2009 Thank you for being so kind in looking into this. 🙏 For the meantime, I removed the code for the month switch (which came from a previous thread below). I tried placing the codes again and it still does not work. I tried using incognito and refreshing the page multiple times. The block from #block-2cd3c3f72a1a11967dd0 and the placeholder search bar translation does not work still. Have I ruined the code injection? Some still work though. 😞 Thank you so much! Link to comment
paul2009 Posted July 19, 2022 Share Posted July 19, 2022 There are lots of different scripts on your site and not all of them are well written, so it is difficult to know where to start 🤣. Perhaps you can get a developer to run through each script one at a time with you and help you to improve them. With a little help you could make each script less fragile (so they do not break when you add new scripts) and improve overall site performance by avoiding repeated code. Naomi-lifelab 1 Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥. Work: Founder of SF.DIGITAL. We provide high quality original extensions to supercharge your Squarespace website. Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links. Forum advice is completely free. You can thank me by selecting a feedback emoji. Buying a coffee is generous but optional. Would you like your customers to be able to mark their favourite products in your Squarespace store? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment