Usage of <can_be_empty> tag for system configuration multi-select field

Suppose say you have following multi-select field in System > Configuration:

Multi-Select Field - Customer Groups
Multi-Select Field – Customer Groups

which is defined by following XML code (partial):
File: app/code/local/MagePsycho/Demomodule/etc/system.xml


...
<allowed_groups translate="label">
	<label>Main Website / Main Store / English</label>
	<frontend_type>multiselect</frontend_type>
	<source_model>demomodule/system_config_source_customergroups</source_model>
	<sort_order>10</sort_order>
	<show_in_default>1</show_in_default>
	<show_in_website>1</show_in_website>
	<show_in_store>1</show_in_store>
</allowed_groups>
...

When you try to de-select the only one selected option from the multi-select field(refer the above snap) and save the config, you will notice that option is not de-selected. In short, config cannot save the multi-select field with empty selection. You may feel that it’s a bug in Magento but unfortunately, it’s not a bug, it’s a feature :). If you want to select none of the options from the multi-select field, you need to use the tag: <can_be_empty> with value = 1 as:


...
<allowed_groups translate="label">
	<label>Main Website / Main Store / English</label>
	<frontend_type>multiselect</frontend_type>
	<source_model>demomodule/system_config_source_customergroups</source_model>
	<sort_order>10</sort_order>
	<show_in_default>1</show_in_default>
	<show_in_website>1</show_in_website>
	<show_in_store>1</show_in_store>
	<can_be_empty>1</can_be_empty><!-- Note this line -->
</allowed_groups>
...

So from above, it is clear that usage of <can_be_empty> with value 1 allows the empty selection for the multi-select field.
The logic behind this goes as:
if <can_be_empty> is true, the system renders a hidden field on the System Configuration page
File: lib/Varien/Data/Form/Element/Multiselect.php

if ($this->getCanBeEmpty()) {
    $html .= '<input type="hidden" name="' . parent::getName() . '" value="" />';
}

[Ref: In Depth Magento System Configuration]

Hope this demystifies the usage of <can_be_empty> for system configuration multi-select field.

Thanks for reading.