Mandatory text after default value text?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2023 02:32 AM
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 -
How do I achieve this?
Any help would be much appreciated!
Thanks,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2023 03:00 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2023 03:12 AM
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;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2023 03:32 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2023 03:40 AM
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);
}
}