magento2: M2.1.9 : Cannot make all address fields required in customer address edit page (frontend)
I am trying to make all address fields required on the customer address page on the frontend using JavaScript validation, but it does not seem to work. I’m wondering if this is a bug or a feature (I think it tends to be a bug). (related question about this topic on SE)
Preconditions
- Magento 2.1.9
Steps to reproduce
Edit the section in Magento_Customer/templates/address/edit.phtml (or overwrite it in a theme) that is responsible for rendering the additional address lines:
<?php for ($_i = 1, $_n = $this->helper(\Magento\Customer\Helper\Address::class)->getStreetLines(); $_i < $_n; $_i++): ?>
<div class="field additional required">
<label class="label" for="street_<?php /* @escapeNotVerified */ echo $_i+1 ?>">
<span><?php echo $block->escapeHtml(__('Street ' . $_i)) ?></span>
</label>
<div class="control">
<input placeholder="<?php echo $block->escapeHtml(__('Street ' . $_i)) ?>"
type="text"
name="street[]"
value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getStreetLine($_i+1)) ?>"
title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Street Address %1', $_i + 1)) ?>"
id="street_<?php /* @escapeNotVerified */ echo $_i+1 ?>"
class="input-text required-entry">
</div>
</div>
<?php endfor; ?>
Note: the only thing I added is the required-entry-class.
Expected result
- Upon submitting the page should show the JavaScript validation message on all address fields
Actual result
- The page just submits, even when the additional address fields are empty.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (12 by maintainers)
Commits related to this issue
- Fix #12202 Fix the issue #12202 — committed to nadeefit6/magento2 by nadeefit6 6 years ago
- Merge pull request #1 from nadeefit6/#12202 Fix #12202 — committed to nadeefit6/magento2 by nadeefit6 6 years ago
- Fix #12202 — committed to nadeefit6/magento2 by nadeefit6 6 years ago
- Update magento2/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml Fix issue #12202 — committed to nadeefit6/magento2 by nadeefit6 6 years ago
why this fix wasn’t added to magento 2.3? WTF o_O? are you so fucking lazy? It was ONE line of code and it took you over 3 fucking years to fix it. I’m speechless
Even in the EE wasnt added 🤦
@hostep @sdzhepa I am able to reproduce issue on 2.3-develop. Case 1: Add
required-entryclass to additional address fields inMagento_Customer/templates/address/edit.phtmlCase 2: Create module with template file where name of the input field is an array
@sdzhepa: not tested yet, but I think https://github.com/magento/magento2/pull/15383 fixed it and that was delivered in Magento 2.3.3 Maybe @kanduvisla can confirm? It also fixed his very similar sounding issue https://github.com/magento/magento2/issues/8258
Update: it looks like https://github.com/magento/magento2/pull/15383 was partly reverted again in MC-19684 for some reason, so not sure if it is truly fixed in 2.3.3 …