1

When editing an entry (actually it's a product within Craft Commerce but everything seems the same) with a pre-existing date, the field looks like this:

<input name="fields[date][date]" value="06/12/2016">

But when re-saving the entry it won't save if I leave the date the same. I'm not getting any errors. If I change the date and re-save the entry, all is fine. Any ideas?

2
  • I'm guessing some validation error. Is anything coming back from entry.getErrors()?
    – Brad Bell
    Commented Oct 27, 2016 at 16:48
  • All I'm getting from entry.getErrors() is the date field being blank if I leave it blank. As I'm not leaving it blank, no error is being returned, but it's clearly failing the validation somehow. To be clear, changing the value of the field to 07/12/2016 will save the product. No other changes. But leaving the field value the same will not let the save go through, there are no errors and nothing in the logs. Commented Oct 31, 2016 at 13:34

1 Answer 1

1

Something I'd not done with the edit form was replace [new1] with [{{variant.id}}] for the variant inputs. As I said, the form was saving correctly anyway if I changed the date, so I didn't expect correcting these to fix the issue I'd been having.

It turns out that correcting these does in fact fix the issue I was having with saving products with an unchanged custom date field. Here is the corrected template code:

{% if variant is defined %}
  <input type="hidden" name="variants[{{ variant.id }}][unlimitedStock]" value="">
  <input type="hidden" name="variants[{{ variant.id }}][minQty]" value="">
  <input type="hidden" name="variants[{{ variant.id }}][maxQty]" value="">
  <input type="text" value="{{ variant.stock }}" name="variants[{{ variant.id }}][stock]">
  <input type="text" value="{{ variant.price | number_format(0) }}" name="variants[{{ variant.id }}][price]">
{% else %}
  <input type="hidden" name="variants[new1][unlimitedStock]" value="">
  <input type="hidden" name="variants[new1][minQty]" value="">
  <input type="hidden" name="variants[new1][maxQty]" value="">
  <input type="text" value="" name="variants[new1][stock]">
  <input type="text" value="" name="variants[new1][price]">
{% endif %}

I'm left wondering whether only having a single default variant allowed still permits new variants to be submitted, which might explain why I wasn't getting any errors? Similarly, I'm not sure why correcting the variant field names fixed the problem I was having with the custom date field not saving when the date wasn't changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.