Show text fields based on the number selected

Prudhvi Raj4
Tera Guru

Hello Team, We have a requirement to show free text fields based on the number entered on the quantity field, for example if user enter 3 in the quantity field 3 text fields should be visible if 5 is the quantity 5 text fields should be visible is there away to achieve this?

 

Thanks,

Prudhvi

1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage
Giga Sage

Hello @Prudhvi Raj4 

 

You can use onChange Client Script :-

 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var value=g_form.getValue('quantity');

for(let i=0; i<value; i++){
// code to visible the fields
}

}

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

View solution in original post

3 REPLIES 3

Samaksh Wani
Giga Sage
Giga Sage

Hello @Prudhvi Raj4 

 

You can use onChange Client Script :-

 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var value=g_form.getValue('quantity');

for(let i=0; i<value; i++){
// code to visible the fields
}

}

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

Barrilito van D
Kilo Guru

Hi Prudhvi, this is what UI policies are made for. You can set visibility of fields based on conditions of other fields. See the documentation here to get started on that.

 

If you think my answer put you in the right direction or you appreciated my effort, please mark the response as Helpful (👍 ) or mark my response as Correct ().
Thanks in advance! Good luck!

Mohith Devatte
Tera Sage
Tera Sage

Hello @Prudhvi Raj4 ,

You can do one thing .

Store the backend names of the text fields in an array and loop the array based on the number entered in the quantity field in an on change client script

 


function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var txt_Arr = ['text_field_1' , 'text_field_2','text_field_3' ,'text_field_4' ,'text_field_5'];
var qnt = parseInt(g_form.getValue('quantity_field_backend_name')); // just in case if the quantity field is string ,converting it to integer

for(vari=0; i<qnt; i++)
{
g_form.setVisible(txt_Arr[i],true);
}

}

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks