How to make field readonly using client script(scoped application)

Jay N
Tera Contributor

Hi Experts,

 

We have a requirement to make reference field (bo_reference) readonly when check box (is bo inherited) is made false and form view should be module_data.

 

Have tried below onload and onchange scripts.

Onchange:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var view = getView();
//alert(view);
var isBOInherited = g_form.getValue('is_bo_inherited');
//alert(isBOInherited);
if (view == 'module_data') {
//if (isBOInherited == 'true') {
if (newValue == 'true') {
g_form.setReadOnly('bo_reference', true);
//g_form.setValue('bo_reference', '');
alert(bo_reference +'bo_reference');
// g_form.setMandatory('bo_reference', 'true');
}
else if (isBOInherited == 'false') {
g_form.setMandatory('bo_reference', 'false');
g_form.setReadOnly('bo_reference', 'true');
}
}
}

 

 

OnLoad:

function onLoad() {

var view = getView();
//alert('view is = ' + view);
var isBOInherited = g_form.getValue('is_bo_inherited');
// alert(isBOInherited);
//bo_referenceISEMPTY
if (view == 'module_data') {
if (isBOInherited == false) {
g_form.setMandatory('bo_reference', false);
g_form.setReadOnly('bo_reference', true);
} else {
g_form.setReadOnly('bo_reference', false);
g_form.setMandatory('bo_reference', true);
}
}

//Type appropriate comment here, and begin script below

}

 

.

 

JayN_0-1669200315588.png

 

Thanks Jay.

5 REPLIES 5

Community Alums
Not applicable

Hi @Pravalika1 @Jay N 

 

In your onchange client script, make the below change:

 

bhavaniy_0-1669267031422.png

In else if block, try g_form.setReadOnly('bo_reference', false); instead of making it true.

 

Please mark my response as helpful/correct if this helps