Jump to content

Is there something wrong with Code Injection? Multiple codes not working.

Recommended Posts

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)

1661584383_lifelabprobono.thumb.png.9e71df19b72d36ba5038bf4e7c8ed638.png

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 by Naomi-lifelab
clicked enter immediately
Link to comment
  • Naomi-lifelab changed the title to Translated form field injection code not working SS7.0 Brine
  • 4 weeks later...

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=
242025143_Typetosearch.thumb.png.30f864bc1424f3ea3761407397fec23a.png

<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 hier

Link: https://lifelab.world/de/spaces
1661584383_lifelabprobono.thumb.png.9e71df19b72d36ba5038bf4e7c8ed638.png.c11b495cf466fb3f275f5a52044efaf5.png

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
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.

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment
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
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 🙂

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment
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

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. 

Improve your online store with our extensions.
About: Squarespace Circle Leader since 2017. I value honesty, transparency, appreciation and great design ♥.
Work: Squarespace Developer and founder of SF Digital, building the features Squarespace didn't include™.
Content: Links in my posts may refer to SF Digital products or may be affiliate links.

Buy me a coffee

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.