magento-lts
magento-lts copied to clipboard
Make it possible to unset the default of a select attribute
Right now, the optional default option is selected with a radio
HTML element. Once one is chosen, it cannot be removed. This leads to bloated data (all products will get this default value, while otherwise the value will not exist). Bloated EAV tables are bad, we should make it possible to not select any default:
No default is okay as long as nothing is selected:
No going back after selecting one:
This only affects dropdown
attributes, not multiselect
attributes.
I second this feature request. It is a good idea to be able to deselect a set default.
If you search in the HTML documentation regarding radio buttons you will find that once selected an option cannot be changed. It will always remain one of the options. In order to obtain that behavior, changes must be made in JavaScript or jQuery.
A JavaScript implementation looks like this:
<input type = radio name = foo id = foo value = var>
<input type = button value = "Uncheck" onclick =
"document.getElementById ('foo'). checked = false">
and the one in jQuery looks like this:
<input type = 'radio' name = 'radioBtn'>
<input type = 'radio' name = 'radioBtn'>
<input type = 'radio' name = 'radioBtn'>
$ (document) .on ("click", "input [name = 'radioBtn']", function () {
thisRadio = $ (this);
if (thisRadio.hasClass ("imChecked")) {
thisRadio.removeClass ("imChecked");
thisRadio.prop ('checked', false);
} else {
thisRadio.prop ('checked', true);
thisRadio.addClass ("imChecked");
};
})
Resources for achieving this task can be found on the Internet if you search with Google for the following words deselect radio button javascript.
@ADDISON74 does this project have any guideline as to which of those 2 solutions is preferred?
There is no PR for this feature.
I wouldn't add a new (radio) button but maybe something like:
onclick = "if (this.checked) this.checked=false">
could work?
I think there are still places in Magento where if you select an radio option you can not return to the initial state. Possible in Custom Options section when editing a product but I did not check it.
I would review these sections of Admin area in the pages source code such as html tags or classes and I would introduce the change in the JS used by the theme, instead of modifying who knows what custom templates.
I'm surprised this problem still exists, actually. It's been a problem since forever. I second the +1