Disable remove row (X) in a MRVS

MiliReinoso
Tera Contributor

Hi, I'm writing a script to disable a few buttons of a MRVS, but my script doesn't work with the remove rox (x). I'm seeing a few post about it but the scripts that i saw didn't work either, I believe it's something wrong with what i wrote. I will let more information about it down below. 

function onCondition() {

    var daysOfWeek = [{
            name: "Monday",
            isWeekday: true
        },
        {
            name: "Tuesday",
            isWeekday: true
        },
        {
            name: "Wednesday",
            isWeekday: true
        },
        {
            name: "Thursday",
            isWeekday: true
        },
        {
            name: "Friday",
            isWeekday: true
        },
        {
            name: "Saturday",
            isWeekday: false
        },
        {
            name: "Sunday",
            isWeekday: false
        }
    ];

    var varValues = [];

    daysOfWeek.forEach(function(dayObj) {

        varValues.push({
            days: dayObj.name,
            start_time: '',
            end_time: '',
            select_if_you_work: dayObj.isWeekday ? 'Yes' : 'No'
        });
    });

    g_form.setValue('business_hours', JSON.stringify(varValues));

    var my_var = g_form.getField("business_hours"); //use your variable set name here
    //The number below indicates after how many rows, the add button to disaable. 
    //If you want to limit to 5 rows then mention 5 below. 
    //If you put 0, it will disable Add button without checking the rows.
    my_var.max_rows_size = 5;

    //MRVS is loaded after the catalog item is loaded. Hence setting a delay of 1 secs.
    setTimeout(function() {
        disableButtons();
    }, 2000);

    function disableButtons() {
        var my_var = g_form.getField("business_hours"); //use your variable set name here
        my_var.max_rows_size = 0;
        var btn = this.document.getElementsByClassName("btn btn-default");
        for (i = 0; i < btn.length; i++) {
            if (btn[i].innerText == 'Remove All') {
                btn[i].disabled = "disabled";
                //If you want to hide it fully, then use below line.
                //btn[i].style.display='None';
            }
        }
        //if you want to hide Add button as well, you can use above logic, 
        // but use the class name as btn-primary instead of btn-default 
        //and change the if condition to Add.
        //MRVS is loaded after the catalog item is loaded. Hence setting a delay of 1 secs.

        //Hide each X (delete row) icon on MRVS
        var icon = this.document.getElementsByClassName('wrapper-xs fa fa-close');
        for (j = 0; j < icon.length; j++) {
            if (icon[j].getAttribute("title") == 'Remove Row') {
                icon[j].style.display = 'None';
            }
        }
    }
}

 

0 REPLIES 0