- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 03:17 AM
Hi there,
we have a ui action with following script:
function par_req() {
var gm = new GlideModal("glide_prompt", true, 1600);
gm.setTitle("Create Product Allocation Requests");
gm.setPreference("title", "Number of Allocations Required (Max 50)");
gm.setPreference("onPromptComplete", function(value) {
g_form.setValue('number_of_product_request', value);
g_form.save();
gsftSubmit(null, g_form.getFormElement(), 'add_product_allocation_requests');
});
gm.render();
}
when user clicks on it, it will show like below:
Ideally we are setting the value in a field, That field is of type integer. But If user enters alphabets, we have to show error.
For ex, if user enters 4a, I have to show error saying the please enter only number. Also if user tries to submit, do not let them submit it.
Is there any way I can perform the validation in UI action? Any references.
Please let me know. Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 03:34 AM
Hi @Naga Ravindra R ,
Can you try this
function par_req() {
var gm = new GlideModal("glide_prompt", true, 1600);
gm.setTitle("Create Product Allocation Requests");
gm.setPreference("title", "Number of Allocations Required (Max 50)");
gm.setPreference("onPromptComplete", function(value) {
if (!isNaN(value)) {
var intValue = parseInt(value, 10);
if (intValue >= 1 && intValue <= 50) {
g_form.setValue('number_of_product_request', intValue);
g_form.save();
gsftSubmit(null, g_form.getFormElement(), 'add_product_allocation_requests');
} else {
alert("Please enter a number between 1 and 50.");
}
} else {
alert("Please enter only numeric values.");
}
});
gm.render();
}
Please mark as Accepted as Solution !!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2024 06:05 AM
Guys, I did something like this and it's working fine.
function par_req() {
var gm = new GlideModal("glide_prompt", true, 1600);
gm.setTitle("Create Product Allocation Requests");
gm.setPreference("title", "Number of Allocations Required (Max 50)");
gm.setPreference("onPromptComplete", function(value) {
if (isNaN(value)) {
alert("Please enter number only");
gm.destroy();
} else {
g_form.setValue('number_of_product_request', value);
g_form.save();
gsftSubmit(null, g_form.getFormElement(), 'add_product_allocation_requests');
}
});
gm.render();
}
Thank you so much @Sohithanjan G.