Skip to main content

Search

Need help with a expression

Comments

1 comment

  • ArdeviaForum

    Original Post by iryna (Imported from Ardevia Forum)

    There are no direct possibility to disable some options of radiobutton field depending on the condition.

     

    But the following trick gives needed result:

     

    1. Select your radiobutton field
    2. Open Expression Builder for 'Enabled' control
    3. Select 'Function code'
    4. Insert the following code example and replace list names with your values

     

    The first example disables only one radiobutton for the selected month if day is more than 15:

     

    NJFJaEsCVmOfxrgisWVsLulYr7uSj8.pnghttps://monosnap.com/file/NJFJaEsCVmOfxrgisWVsLulYr7uSj8.png

     

    Code:

     

    if ([[YourDateField]]){
    var selectedMonth = [[YourDateField]].getMonth();
    var selectedDay = [[YourDateField]].getDate();
    
    if(selectedDay > 15)
      setTimeout(function(){
          jQuery('span[fieldname=YourRadiobuttonField] input[type=radio]')[selectedMonth].disabled = true;
      },100);
    }
    return true;
    

     

    Second example disables all months options that are less than selected date:

     

    RBCjthm7vQx1KRCnSvEZP7oZily8KG.pnghttps://monosnap.com/file/RBCjthm7vQx1KRCnSvEZP7oZily8KG.png

     

    Code:

     

     

    if ([[YourDateField]]){
    var selectedMonth = [[YourDateField]].getMonth();
    var selectedDay = [[YourDateField]].getDate();
    
    
      setTimeout(function(){
        for(var i=0;i<=selectedMonth;i++)
        {
          if(i!=selectedMonth || selectedDay > 15)
          jQuery('span[fieldname=YourRadiobuttonField] input[type=radio]')[i].disabled = true;
        }
      },100);
    }
    return true; 
    

     

     

     

    For the dropdown choice field, the code should be as following:

     

    Code:

    if ([[YourDateField]){
    var selectedMonth = [[YourDateField]].getMonth();
    var selectedDay = [[YourDateField]].getDate();
    
    if(selectedDay > 15)
      setTimeout(function(){
          jQuery('span[fieldname=YourDropdownField] option')[selectedMonth].disabled = true;
      },100);
    }
    return true; 
    
    0

Please sign in to leave a comment.