onChange script for stop record submission if the validation doesn't meet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 04:29 AM
Hi Community,
I have a requirement that the field length should be minimum 25 characters with no blank space. If the validation doesn't meet an alert message should pop-up and shouldn't allow to save the record. I have written a onChange script, it is showing the pop-up message however it is allowing to save the record. Please help me in how to restrict to save the record if the validation doesn't meet?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 04:46 AM
Hi @JaganN971616731 ,
You have to return false in order to stop form submission. I have added it in your code, and below is the modified version of your code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var char = newValue.toString();
var str = char.replace(/ /g, "");
if (str.length < 25) {
alert('Problem statement should have minimum 25 characters excluding spaces.');
//============================================================
return false;
//============================================================
}
}
Thanks,
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 05:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 05:30 AM
Hi @JaganN971616731 ,
Remove the alert form the code, and if it works after that, then you can use AddErrorMessage instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 09:48 AM
Hi @JaganN971616731 ,
OnChange client script is good you can keep it, but I think you need one more Client Script OnSubmit to check the field value before submit and throw error message because onChange client script wont prevent user from submitting the record.
something like this:
var fieldValue= g_form.getValue("field_name");