Mandatory text after default value text?

alex2410
Tera Contributor

Hi All,

 

I have variables with a default value but would like to make this field mandatory, e.g. the user has to put in extra text in order to submit the catalogue item - 

 

Capture.PNG

How do I achieve this?

 

Any help would be much appreciated!

Thanks,
Alex

5 REPLIES 5

Priyanka0402
Mega Sage
Mega Sage

Hello @alex2410 ,

You can create 2 OnChange Client scripts for Summary and Description. and if the variable is != '' then make it mantatory.

Here is the code for the Summary. Create a similar OnChange for the Description as well.

 

function onChangeSummary() {
var summaryField = g_form.getValue('summary');

if (summaryField.trim() !== '') {
g_form.setMandatory('summary', true);
} else {
g_form.setMandatory('summary', false);
}
}

 

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

Regards

Priyanka

Manmohan K
Tera Sage

Hi @alex2410 

 

You can use below on submit client script to set the fields mandatory if they are not changed by user

(change backend name of variables if needed)

 

function onSubmit() {
    var field1 = g_form.getControl('summary'); //Get the 'Caller' field control
    var field2 = g_form.getControl('description'); //Get the 'Short description' field control

   
    if (!field1.changed) {
        g_form.setMandatory('summary', true);
    }
    if (!field2.changed) {
        g_form.setMandatory('description', true);
    }
    if (field1.changed && field2.changed) {
        return true;
    }
    return false;
}

 

Hello, thanks for your reply!

The first step is working, it is making the fields mandatory on submit with no change.

But after I make a change to the fields, and submit, it still does not let me submit the cat item, any ideas?

Thanks!
Alex

Try with below script

function onSubmit() {
    var field1 = g_form.getControl('summary'); //Get the 'Caller' field control
    var field2 = g_form.getControl('description'); //Get the 'Short description' field control

   
    if (!field1.changed) {
        g_form.setMandatory('summary', true);
    }
    if (!field2.changed) {
        g_form.setMandatory('description', true);
    }
    
}