GlideModal help

Naga Ravindra R
Kilo Sage

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:

 

NagaRavindraR_0-1708946046798.png

 

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

1 ACCEPTED SOLUTION

Sohithanjan G
Kilo Sage
Kilo Sage

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 !!!

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

View solution in original post

5 REPLIES 5

Naga Ravindra R
Kilo Sage

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