35
Views
7
Comments
Solved
Limit the input list parameter length for the block
Question
Application Type
Reactive

I have a block that accepts a list as an input parameter. Now I want to add a restriction that the list length must be 2 or more whenever this block is utilized in any screen or other block.

How can I achieve this?


2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution


still not really getting it, are you afraid of developers using your widget when it is not really appropriate?  What is the worst that can happen, it only offers one option, and that looks a bit weird in the UI as that is not what it is meant for ?  Testers / PO will catch that sort of problem.

Also mitigate that by offering clear description of your widget.

To enforce this, you could make it real obvious by making the widget refuse to perform when only 1 option is passed to it, such as just showing an error in that case instead of the option passed in.  I would not choose for this type of drastic approach.

The best i can come up with, is to check this in the OnInitialize and OnParametersChanged of your block at runtime, and log a message every time it is used with only 1 option.

Dorine 

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Vrushali Punekar ,

Most lists will only be known at runtime, some might be hardcoded in some way and known at design time.

For both, at runtime, you can add a check both in the onInitialise and in the OnParametersChanged.  What exactly do you want to happen if your criterium is not met ?

at design time (for hardcode lists), not sure if there is a way, other than doing a code review, by doing a find usage on your block and inspecting what is getting passed in.

Dorine

UserImage.jpg
Vrushali Punekar

Hi @Dorine Boudry 

This limitation must exist at the time of design. 

Is there a workaround for this?

2021-09-06 15-09-53
Dorine Boudry
 
MVP

how could you possibly know, lots of lists only get created at runtime.  

Can you say more about why you need there 2 be at least 2 things, cause that sounds like an odd requirement to begin with.

UserImage.jpg
Vrushali Punekar

I am using block to build a custom widget, and it has a list as an input parameter.

This list will show possibilities for selection, and the need is to have at least two options for selection.

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution


still not really getting it, are you afraid of developers using your widget when it is not really appropriate?  What is the worst that can happen, it only offers one option, and that looks a bit weird in the UI as that is not what it is meant for ?  Testers / PO will catch that sort of problem.

Also mitigate that by offering clear description of your widget.

To enforce this, you could make it real obvious by making the widget refuse to perform when only 1 option is passed to it, such as just showing an error in that case instead of the option passed in.  I would not choose for this type of drastic approach.

The best i can come up with, is to check this in the OnInitialize and OnParametersChanged of your block at runtime, and log a message every time it is used with only 1 option.

Dorine 

UserImage.jpg
Vrushali Punekar

Actually this restriction is part of the requirement.

However, we can implement the checks which you have suggested.

Thank you.

2023-10-21 19-42-11
Tousif Khan
Champion

Hello 

You can check the condition via a length property of a list, 

You can check the condition in a List.

If list.length >1 then true otherwise false

hope this helps

Thanks

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.