CA Service Management

 View Only
  • 1.  Checking if there are any items in a dual list select box

    Posted 30 days ago

    I am building a Catalog form in which I want to make one of the fields 'required' if one or more items have been selected in a previous dual list select box. 

    I have tried multiple different options but either the field becomes required if nothing is selected in the previous select box, or it doesn't become required if something has been selected. N.B. 'duallist_2' is the name of the dual list field and 'selected_list_2' is the name of the Right Container Label. 

    These are some of my attempts:

    $(ca_fdGetSelections('form1','duallist_2.selected_list_2').count>0)

    $('form1','duallist_2.selected_list_2'.count>0)

    Can someone help me with the correct syntax?

    Thanks very much.



  • 2.  RE: Checking if there are any items in a dual list select box

    Broadcom Employee
    Posted 20 days ago

    Hi Patrick,

    Apologies for the delayed response. I have responded to your support case as well. 

    The Form Element attributes are not dynamic, they will be evaluated only once while rendering. Also required attribute cannot be dynamically controlled with any form API's, we can have a required field and show/hide this field based on our logic.

    To achieve the required behavior, we have to use the duallist "onchange" attribute and form script as below to show the required field only if there are any selections in the dual list field.

     

    Form Script:

    {
     setRoleField: function(){
       if(ca_fdGetSelections(ca_fd.formId,'duallist_1').length > 0){
         ca_fdShowField(ca_fd.formId,'roles_1');
       }else{
         ca_fdHideField(ca_fd.formId,'roles_1');
       }
     }
    }

     

    onChange attribute of Dual list component: ca_fd.js.setRoleField();

     

    Make the "required" and "hidden" attributes of roles_1 text field as true

     

    Regards,

    Satya Kiran