OptionField options from Dynamic Array column

Hi all,

In my Parametrization class I have several input steps with a couple of arrays. In one of the later steps I want to select a certain value in one of these array columns but I’m not able to correctly do this with the (Row)Lookup functionalities as these are not iterable. Is there any method of looking up values in a different Dynamic Array column?

Thanks in advance.

Cheers!

Hi Jelle,

Thank you for your question. If I understand you correctly, you would like to have the values that were filled in a previous step as possible options to select in a next step 2, within an array, right? If so, let us take a look a the example I have set up:

def options_of_array_1(params, **kwargs):
    return [OptionListElement(label=row.label, value=row.value) for row in params.step_1.array_1]


class Parametrization(ViktorParametrization):
    step_1 = Step('Step 1')
    step_1.array_1 = DynamicArray('Array 1')
    step_1.array_1.label = TextField('Label')
    step_1.array_1.val = NumberField('Value')
    
    step_2 = Step('Step 2')
    step_2.array_2 = DynamicArray('Array 2')
    step_2.array_2.options_array_1 = OptionField('Options from array 1', options=options_of_array_1)

In the snippet I provided, you have two steps (step 1 and step 2). Both have arrays, with the one in step 1 having two columns, “Label” and “Value”. By using a callback function, you can write the logic you want to complete a list that can be used in another OptionField. By setting up a second dynamic array in step 2 with an OptionField as a column, the options that can be set on that field can be done with the function that was defined (in the snippet the function options_of_array_1 was used).

In my example I used a list of OptionListElement objects. This can also be achieved by only using a list of values, if you do not want to differentiate between the values and labels.

I hope this helps. If not, could you elaborate what you would like to achieve with a simple example?

1 Like

Hi Marcel,

thanks for your elaborate reply! The callback function did the trick and everything is working perfectly now!

Cheers!

1 Like