How to make a field mandatory inside the widget on change of a field value in widget ?

bala_1312
Tera Contributor

there is  a drop down field in a widget so when the values will be changing then i need to make  a input type ="text" field mandatory , how to achieve that please advise .

 

Thanks!

6 REPLIES 6

Mohan raj
Mega Sage

Hi @bala_1312,

 

To make field mandatory in widget, need to use html attributes required 

<input type="text" id="username" name="username" required>

 

If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.

Regards,

Mohan.

Hi @Mohan raj ,

It should be dependent on dropdown field , it should not be mandatory by default .

Priyanka0402
Mega Sage
Mega Sage

Hello@debo jyoti ,  you can use the OnChange client script.

 

function DropdownChange() {

    var dropdownValue = g_form.getValue('myDropdownName');

    var textField =g_form.getValue('myInputFieldName');

    

    if (dropdownValue === 'someValueYouWant') {

        textField.required = true;

    } else {

        textField.required = false;

    }

}

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards

Hi @Priyanka0402 ,

Where should i write this script ? inside client controller or is it  catalog client script ?