magento-lts icon indicating copy to clipboard operation
magento-lts copied to clipboard

Make it possible to unset the default of a select attribute

Open loekvangool opened this issue 3 years ago • 7 comments

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: image

No going back after selecting one: image

This only affects dropdown attributes, not multiselect attributes.

loekvangool avatar Aug 27 '21 09:08 loekvangool

I second this feature request. It is a good idea to be able to deselect a set default.

Sdfendor avatar Aug 27 '21 12:08 Sdfendor

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 avatar Aug 29 '21 17:08 addison74

@ADDISON74 does this project have any guideline as to which of those 2 solutions is preferred?

loekvangool avatar Sep 03 '21 08:09 loekvangool

There is no PR for this feature.

addison74 avatar Sep 03 '21 09:09 addison74

I wouldn't add a new (radio) button but maybe something like:

onclick = "if (this.checked) this.checked=false">

could work?

fballiano avatar Sep 03 '21 17:09 fballiano

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.

addison74 avatar Sep 03 '21 19:09 addison74

I'm surprised this problem still exists, actually. It's been a problem since forever. I second the +1

henryhayes avatar Nov 28 '21 19:11 henryhayes