g_form.setValue works in classic form view but not work in workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2024 08:12 PM
I would like to add a new field in a hr case under workspace. The field can only accept exactly 8 integer numbers. A alert will pop up and then clear the field input value if input value doesn't pass validation.
Therefore, I created a new field 'new_position_number' in table 'sn_hr_core_case'. The type of field is String with max length=8. And created a client script as below to restrict the user to input 8 integer numbers.
I tested the client script in Workspace and it works for the first time. Once user input a value that didn't pass the validation, an alert popped up and then field value was cleared. The case in workspace changed the state to 'You have unsaved changes in workspace'. However, when I tested the script again, the alert could pop up but system didn't clear the field value. While this client script always works in classic form view.
How do I modify the script to make it work in Workspace? thanks.
client script:
UI Type is All
Isolate script is checked
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regExTest = /(^[0-9]{8}$)/;
if(!regExTest.test(newValue)){
alert("Please enter exactly 8 numbers");
g_form.setValue('new_position_number', ' ');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 10:54 AM - edited 02-11-2024 10:57 AM
You should not clear the value at all - that is bad user experience.
Say the user mistakenly added a numeral twice.
All the user would need to do to fix this is to delete the extra numeral.
Or perhaps forgot to add one numeral and the user would just need to add the missing one.
But if you clear the value you are forcing the user to re-enter 7 or 8 of the already correct numerals again.
It would be for more user friendly and the would be a far better user experience if you would show a message below the field and you would do the check on submit - leaving it to the user on how to correct the number entry.
Also, don't user alert (modal boxes in general, like confirm, or prompt, etc...) - that is so past millennium; also bad UX design, it interrupts the user workflow.
Showing a message ribbon below the faulty field is way better user experience.