Magento version: 2.1.2
It is not possible to unselect and save all multiselect attribute values for a product.
After the save completes the state of the product attribute before the product was saved is unchanged.
It seems the problem is that the JS does not submit multiselect form elements with no selected values, at least on the server side completely unselected multiselect attribtues are not part of the $_POST['product'] array.
The exact same issue existed for years on M1 but was finally fixed there. It seems like this issue was introduced again for M2.
None special.
features_bag or strap_bags attributes). The product attribute should have no value for the product.
The previously selected product attributes still are selected.
@fooman gave the input that probably the can_be_empty property has to be set on the \Magento\Framework\Data\Form\Element\Multiselect instance.
For system configuration multiselect that can be done by adding the <can_be_empty> node to the system.xml file, but in case of EAV attributes I see no obvious way to do so since they are DB based.
On a side note, the method \Magento\Framework\Data\Form\Element\Multiselect::getElementHtml() adds the CSS class admin__control-multiselect (amongst others). Should the class not also be usable on the store front?
More info in case it's useful: the property can_be_empty would be set in \Magento\Backend\Block\Widget\Form::_applyTypeSpecificConfig() but that method is never called. There are 3 classes that would trigger the flow of control to enter that method, but none of three classes are used on the edit product form. Is this M1 legacy code that wasn't deleted?
\Magento\Catalog\Block\Adminhtml\Product\Edit\Action\Attribute\Tab\Attributes::_prepareForm()
\Magento\Catalog\Block\Adminhtml\Product\Attribute\NewAttribute\Product\Attributes::_prepareForm()
\Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Attributes::_prepareForm()
It seems that same problem exists with configuration multiselects. For example
Stores>Configuration>General>Top destinations - not possible to unselect all and save in 2.1.2.
Hi @Vinai , thanks for reporting this issue. We have internal ticket MAGETWO-57607 to track this issue on our side.
Best,
Anton.
It happens also on custom attributes with custom sources. I have put _Magento\Eav\Model\EntityAttributeBackendArrayBackend_ as _backend_model_ .
When i save in backoffice without options, i have a string in the before save with the previous options selected.
When i save in backoffice with one/more options, i have an array.
@antboiko Any update on this issue? A Magento Enterprise merchant I'm working with is experiencing this issue and they're looking for a patch. Before emailing support for a patch, I wanted to see if this was fixed in develop so that I can grab a patch?
Any update on this?
I'd like to know how to get this fixed. It's driving me nuts. (Tested on both 2.1.2 and 2.1.6)
Bug is still present in 2.1.5.
Seems like duplicate of #6253 #6281 #4545
and that this is fixed by
https://github.com/nagno/magento2/commit/b380502570b92449326ab6ed50e6ce0359287240
This issue was fixed in develop branch.
It also was fixed for ver. 2.1 (internal ticket - MAGETWO-57607) and fix will be available in one of the nearest releases.
We were not able to reproduce this issue for ver. 2.0.
@Vinai, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
@veloraven @magento-engcom-team Do you know where this was fixed for the 2.1 branch? I see the backport commit here but this does not fix the issue for me (introduces a new issue): https://github.com/magento/magento2/commit/7ec895235782c4195bc3363eb63fd5a15754930b
If there's a better place for me to describe the issue please let me know.
This issue still persist in Magento ver. 2.2.2
Still present in Magento ver. 2.2.3
I had the same issue because of multiselect having an empty value (ie. equal to '' or 0 or null) :
<select multiple="" class="admin__control-multiselect" data-bind="
attr: {
name: inputName,
id: uid,
size: size ? size : '6',
disabled: disabled,
'aria-describedby': noticeId,
placeholder: placeholder
},
hasFocus: focused,
optgroup: options,
selectedOptions: value,
optionsValue: 'value',
optionsText: 'label'" name="product[customer_group]" id="MEAKNUP" size="6" aria-describedby="notice-MEAKNUP">
<option data-title="NOT LOGGED IN" value="0">NOT LOGGED IN</option> <!-- here is the devil -->
<option data-title="General" value="1">General</option>
<option data-title="Conseill猫re" value="2">Conseill猫re</option>
</select>
Magento\Catalog\ControllerAdminhtml\Product\Initialization\HelperAttributeFilter prepare your attributes before saving it.
public function prepareProductAttributes(Product $product, array $productData, array $useDefaults)
{
foreach ($productData as $attribute => $value) {
$considerUseDefaultsAttribute = !isset($useDefaults[$attribute]) || $useDefaults[$attribute] === "1";
if ($value === '' && $considerUseDefaultsAttribute) {
/** @var $product Product */
if ((bool)$product->getData($attribute) === (bool)$value) {
unset($productData[$attribute]);
}
}
}
return $productData;
}
When a posted value is equal to empty string ('') it will compare it to the product value before saving.
The issue is that Magento cast both values in boolean. And when the previously selected product value was set to 0 (like "NOT LOGGED IN" in our example) it compares an empty string casted in boolean (= false) with a 0 casted in boolean (= false too) so the value is simply unset ... so the attribute isn't saved and there is no error.
In our specific case, we fixed it using a plugin to restore the value after the prepareProductAttributes function has been called.
I hope it will help.
Why this issue is closed?
@likemusic
Why this issue is closed?
- This issue isn't reproduced on current 2.2 and 2.3 Magento branch
Still this issue also persist at magento 2.2.4 .
Have done with Vinai describe scenario and same issue is happening
@Vinai ,Is this issue resolved at your end?
@magento/community-engineering-team ,Can you please check this issue again
I hope this will help someone.
di.xml
<type name="\Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\AttributeFilter">
<plugin name="Vendor_Module::prepareProductAttributes" type="\Vendor\Module\Plugin\Product\AttributeFilter"/>
</type>
PluginAttributeFilter.php
use \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\AttributeFilter as AttributeFilterHelper;
public function afterPrepareProductAttributes(AttributeFilterHelper $subject, $result, $product, $productData)
{
foreach ($productData as $attribute => $value) {
$pos = strripos($attribute, '-prepared-for-send');
if ($pos === false) {
continue;
}
$attr = substr($attribute, 0, $pos);
if (isset($result[$attr])) {
continue;
}
$result[$attr] = '';
}
return $result;
}
@engcom-backlog-nazar @engcom-backlog-nickolas could you please recheck if this issue still there?
People were complaining that it wasn鈥檛 fixed
@ihor-sviziev, ok i will re check this issue
Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.[x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.
[ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.3-develop branchDetails
- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!
[ ] 5. Verify that the issue is reproducible on 2.2-develop branch. Details
- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x
[ ] 6. Add label Issue: Confirmed once verification is complete.
[ ] 7. Make sure that automatic system confirms that report has been added to the backlog.
@ihor-sviziev seems like this already fixed in 2.3.0 release

@engcom-backlog-nazar
@Aurelius15 same with
unselect all items this attribute and try to save
@engcom-backlog-nazar did you checked this issue on 2.2 release line?
@ihor-sviziev yes, same on 2.2-develop
@ihor-sviziev can we close this issue ?
@engcom-backlog-nazar sure, if we can鈥檛 reproduce this issue
I cannot find the fix.
Can we have a patch for the fixes?
Many thanks
i have the same issue for the 2.2.8.. Does the 2.2.x have a fix for that? we are unable to unselect all values :'(
Still an issue on 2.3.5 I'm facing same issue. key pair value not set in the post when all values are deselected.
Note: Fixed multi select in system.xml with can_be_empty.
Most helpful comment
This issue still persist in Magento ver. 2.2.2