1

enter image description hereSuppose, if i change value of test attribute, than color and demo should be pre-filled with earliest selected value.

Can Anyone Help me in this Problem?

4
  • are you talking about multiselect option like we have in selecting more than one store views? Commented Dec 15, 2020 at 7:20
  • yes, same like that Commented Dec 15, 2020 at 7:41
  • If you've multiselect in ui-component form then whatever options you will select before saving will be pre-selected when you edit the form next time. Is this what you mean to ask? Commented Dec 15, 2020 at 9:41
  • try this to store your data: What is Data Persistor?
    – Msquare
    Commented Dec 17, 2020 at 6:35

1 Answer 1

1

You need to override a file vendor\magento\module-configurable-product\view\frontend\web\js\configurable.js

Make changes to a function _configureElement

_configureElement: function (element) {
    this.simpleProduct = this._getSimpleProductId(element);

    if (element.value) {
        this.options.state[element.config.id] = element.value;

        if (element.nextSetting) {
            element.nextSetting.disabled = false;
            var nextId = element.nextSetting.id;
            var nextSelectedVal = $("#" + nextId).val();
            this._fillSelect(element.nextSetting);
            this._resetChildren(element.nextSetting);
            if (nextSelectedVal.length) {
                $("#" + nextId).val(nextSelectedVal);
                $("#" + nextId).change();
            }
        } else {
            if (!!document.documentMode) { //eslint-disable-line
                this.inputSimpleProduct.val(element.options[element.selectedIndex].config.allowedProducts[0]);
            } else {
                this.inputSimpleProduct.val(element.selectedOptions[0].config.allowedProducts[0]);
            }
        }
    } else {
        this._resetChildren(element);
    }

    this._reloadPrice();
    this._displayRegularPriceBlock(this.simpleProduct);
    this._displayTierPriceBlock(this.simpleProduct);
    this._displayNormalPriceLabel();
    this._changeProductImage();
},

Also, to below function,

_resetChildren: function (element) {
    if (element.childSettings) {
        _.each(element.childSettings, function (set) {
            //set.selectedIndex = 0;
            set.disabled = true;
        });

        if (element.config) {
            this.options.state[element.config.id] = false;
        }
    }
},
1
  • Amazing !!! Thank you so much. Keep helping. :) Commented Dec 17, 2020 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.