Hide Attachment on catalog item based on the subcategory

bhanukota09
Tera Contributor

Hi All,

I have a requirement where, based on the user's selection, the URL and attachment variables should be visible and mandatory. Otherwise, the URL and attachment should be hidden.

For this, I have used:

  • A Rich Text variable type for the URL
  • An Attachment variable type for file upload

For implementing the logic, I configured an onChange Client Script.

The issue I am facing is that when I make the attachment mandatory, it does not get hidden when I select other subcategories. The attachment field remains visible, which is incorrect.

In simple terms:

  • If the subcategory is A, B, or C, the attachment should be visible and mandatory
  • If the user selects D to Z, the attachment and URL should be hidden
        var sub = g_form.getValue('subcategory');
        // alert(sub);
        g_form.setVisible('URL', false);
        g_form.setVisible('URL', false);
        g_form.setVisible('URL', false);
        g_form.setVisible('attachment', false);
        g_form.setVisible('attachment2', false);
        g_form.setVisible('attachment3', false);
        // g_form.setMandatory('attachment', false);
        // g_form.setMandatory('attachment2', false);
        // g_form.setMandatory('attachment3', false);

        //alert(sub);
        if (sub == 'A') {
            g_form.setVisible('URL', true);
            g_form.setVisible('attachment', true);
            g_form.setMandatory('attachment', true);
            // g_form.setVisible('attachment2', false);
            // g_form.setVisible('attchment3', false);
            // g_form.setMandatory('attachment2', false);
            // g_form.setMandatory('attachment3', false);
     
        } else if (sub == 'B') {
            g_form.setVisible('URL', true);
            g_form.setVisible('attachment2', true);
             g_form.setMandatory('attachment2', true);
             g_form.setVisible('attachment', false);
            g_form.setVisible('attachmen3', false);
            g_form.setMandatory('attachment', false);
            g_form.setMandatory('attachment3', false);
     
        } else if (sub == 'C') {
            g_form.setVisible('URL', true);
            g_form.setVisible('attachment3', true);
            g_form.setMandatory('attachment3', true);
            g_form.setVisible('attachment', false);
             g_form.setVisible('attachment2', false);
            g_form.setMandatory('attachment', false);
             g_form.setMandatory('attachment2', false);
        }
    }

 

0 REPLIES 0