Conditional table columns

conditional columns

Is it possible to have conditional columns in this context of repeating fields i.e. if the purchaser is a corporate entity, then the columns on an individual are hidden?

Hi Robert,

This is possible, but it requires you to venture into the use of custom functions. The underlying reason is that the types of conditions that you will probably want to use, can get so complex, that the familiar conditions system in the Q&A (with dropdown etc.) will in many cases not be powerful enough.

What you need to do is to select the table in the Q&A editor, and then in the question’s options click the “add question customization” button. Then you need to insert the following code:

(assoc question

       :column-pred-fn
       (fn [question, row-index, column-index, answers-map]
         (let [current-values (get answers-map row-index)]
          (case column-index
            ; company type: enable when answer to 1 (corporate entity) is true
            2 (get current-values 1)

            ; foreign passport?
            4 (not (get current-values 1))

            ; all other columns
            true)))

       :column-caption-fn
       (fn [question, row-index, column-index, answers-map, default-caption, lang]
         (let [current-values (get answers-map row-index)
               company? (get current-values 1)]
           (case column-index
             ; for column 3, differentiate between "registration" and "ID nr."
             3 (if company? "company registration nr." "personal identification nr.")

             ; all other columns: return default-caption
             default-caption))))

(assuming that “purchaser name” is column 0, “corporate entity?” is column 1, etc.)

This code essentially hides the company type & foreign passport when the checkmark for company is not set. Also, if not a company, the label of the ID-number is changed.

I definitely recommend checking out the Help-page I referred to above. Be aware, however, that this is probably the most advanced territory you can venture into within the ClauseBase platform.