We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Custom field not adding anything to cart

Solved

Custom field not adding anything to cart

Vyk
Shopify Partner
17 1 6

Hello, I used to use a custom field in the debut theme; for some reason, on the Dawn theme, this code doesn't add anything to the cart.

I have other custom fields that work perfectly. What might be the reason for that?

 

 

If you have any idea how to fix it, I would be grateful 🙂

 

<p class="line-item-property__field" style="margin-left: 5px; !important;">
   <label>Do you want customization?</label>
   <select id="custom" name="properties[Do you want customization?]">
       <option value="No">No</option>
       <option value="Yes">Yes</option>
   </select>
</p>
<p class="line-item-property__field" id="customName" style="margin-left: 5px !important;">
   <label for="NAME">Names:</label>
   <input class="required" id="Customization" type="text" name="properties[Customization]">
</p>
<script>
  const customField = document.querySelector('#custom');
  const customName = document.querySelector('#customName');
  const personalizacijaInput = document.querySelector('#Customization');

  customName.style.display = "none";
  personalizacijaInput.required = false;

  customField.addEventListener('change', function() {
    if (this.value == "Yes") {
      customName.style.display = "block";
      personalizacijaInput.required = true;
    } else {
      customName.style.display = "none";
      personalizacijaInput.required = false;
      personalizacijaInput.value = ''; // Clear the input value when not required
    }
  });
</script>

 

Accepted Solution (1)

Vyk
Shopify Partner
17 1 6

This is an accepted solution.

Hello, I have found the code that works. Needs just some CSS on it and we good. 🙂

 

<p class="line-item-property__field" style="margin-left: 5px; !important;">
   <label>Do you want to personalize?</label>
   <select id="custom" name="properties[Do you want to personalize?]">
       <option value="No">No</option>
       <option value="Yes">Yes</option>
   </select>
</p>
<p class="line-item-property__field" form="{{ 'product-form-' | append: section.id }}" id="customName" style="margin-left: 5px !important;">
   <label for="NAME">Names:</label>
   <input class="required" form="{{ 'product-form-' | append: section.id }}" id="Personalizacija" type="text" name="properties[Personalization]">
</p>
<script>
  const customField = document.querySelector('#custom');
  const customName = document.querySelector('#customName');
  const personalizacijaInput = document.querySelector('#Personalizacija');

  customName.style.display = "none";
  personalizacijaInput.required = false;

  customField.addEventListener('change', function() {
    if (this.value == "Yes") {
      customName.style.display = "block";
      personalizacijaInput.required = true;
    } else {
      customName.style.display = "none";
      personalizacijaInput.required = false;
      personalizacijaInput.value = ''; // Clear the input value when not required
    }
  });
</script>

 

View solution in original post

Replies 3 (3)

ebrinker
Tourist
3 0 1

Several stores are watching a similar issue that could be a problem on the Shopify side and not necessarily your custom theme. The problem over on this other post started Saturday morning: https://community.shopify.com/c/technical-q-a/post-locale-cart-add-required-parameter-missing-or-inv...

 

Give it a like and response (it might help escalate the issue)

Vyk
Shopify Partner
17 1 6

This is an accepted solution.

Hello, I have found the code that works. Needs just some CSS on it and we good. 🙂

 

<p class="line-item-property__field" style="margin-left: 5px; !important;">
   <label>Do you want to personalize?</label>
   <select id="custom" name="properties[Do you want to personalize?]">
       <option value="No">No</option>
       <option value="Yes">Yes</option>
   </select>
</p>
<p class="line-item-property__field" form="{{ 'product-form-' | append: section.id }}" id="customName" style="margin-left: 5px !important;">
   <label for="NAME">Names:</label>
   <input class="required" form="{{ 'product-form-' | append: section.id }}" id="Personalizacija" type="text" name="properties[Personalization]">
</p>
<script>
  const customField = document.querySelector('#custom');
  const customName = document.querySelector('#customName');
  const personalizacijaInput = document.querySelector('#Personalizacija');

  customName.style.display = "none";
  personalizacijaInput.required = false;

  customField.addEventListener('change', function() {
    if (this.value == "Yes") {
      customName.style.display = "block";
      personalizacijaInput.required = true;
    } else {
      customName.style.display = "none";
      personalizacijaInput.required = false;
      personalizacijaInput.value = ''; // Clear the input value when not required
    }
  });
</script>

 

Easify-Mark
Explorer
169 3 3

Hi @Vyk,

For future reference, you might find the Easify Product Options app (free plan available) really helpful for creating custom fields without any coding. Here’s a quick example of how you can set it up:

  • Product page:

EasifyMark_4-1726632749560.png

EasifyMark_5-1726632760499.png

EasifyMark_6-1726632788425.png

 

  • Simple settings:

EasifyMark_0-1726632580402.png

EasifyMark_1-1726632589955.png

EasifyMark_2-1726632601220.png

EasifyMark_3-1726632611444.png

 

If you want to give it a try, just let me know!

Easify Product Options: Any product options app can help you create custom options, but Easify turns those options into sales and conversions!
Easify Inventory Sync: Automate inventory syncing for Bundles, Duplicates, and Raw Materials. Say goodbye to manual tracking headaches.
Easify Product Attachments: Enrich your store with downloadable content. Easily add PDFs and other files to product or any page.
>>> Try Apps for Free | 24/7 Live Chat Support