Facing Issue Regarding Work Notes

kushagrasah
Tera Contributor

Hi,

I am facing an issue regarding work notes , My use case is that when user enters input in the work notes, if the length of the message is less than 30 , i have to show a error message on the field itself, but this has to be real time while user is writing the message , so for this i used a OnChange client script to show the error message . The issue i am facing is that whenever on the incident form , as soon as i start to write in the work notes, the error message gets displayed and my mouse control ( basically focus ) is  moved out of the work notes, to continue i again have to click in side the textarea.
But what i need is that when the error message gets displayed, the focus should not move out of the work notes textarea and the user should be able to continue writing the message.


Your guidance is greatly appreciated!

2 REPLIES 2

J Siva
Tera Sage

Hi @kushagrasah 
Please share your script if possible. I've tried the below script in my PDI and it's working as expected.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var count = newValue.length;
    if (parseInt(count) > 30) {
        g_form.showFieldMsg("work_notes", "Error message...",'error);
    }

}


Regards,
Siva

function debounce(func, delay) {
    clearTimeout(debounceTimeout);
    debounceTimeout = setTimeout(func, delay);
}

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || !newValue) return;

 

    debounce(function() {
        var words = newValue.trim();
        if((newValue.split(' ').length<4)||newValue.length<20)
        {
            g_form.showErrorBox('work_notes', 'Please type at least 20 characters with 4 words');
            var elementExists = top.window.document.getElementById("activity-stream-work_notes-textarea");
            var ele = top.window.document.getElementById("activity-stream-textarea");
            if (elementExists) {
                top.window.document.getElementById("activity-stream-work_notes-textarea").focus();
            }
            if (ele) {
                top.window.document.getElementById("activity-stream-textarea").focus();
            }

 

        }
    }, 1000);
}


This script is not able to keep focus on my work notes for every user , it works for some of them only