Ui Page:validation in ui page

manishakumari
Kilo Contributor

In Client script of UI page I wrote this :

function onSubmit(){

var comm = document.getElementById('addComments').value;

//var comm = gel('addComments').value;

if(comm == ''){

alert('Please fill Comments ');

return false;

}

else{

alert(comm);

g_form.setValue('work_notes',comm);

GlideDialogWindow.get().destroy();

return true;

}

}

I am able to get the comm value.....But it is not validating for null...It always execute else part....

Could you please tell me why this condition is not met if(comm == '') ........if I am not filling anything in comment field

3 REPLIES 3

Gaurav Bajaj
Kilo Sage

Hi,


There seems to be a syntax error.



if(comm == '' "){



alert('Please fill Comments ');


return false;


}



Please use the highlighted part as your code.


mayurt
Tera Expert

Hi Monu ,



There might be the case some undefined values are coming and every time it is going to else loop please try below thing :


if(comm == null)



Kind Regards,


Mayur Tejnani


Andrew Bettcher
Kilo Sage

I was stuck on the same thing and found this page. Noted that there was no real answer and I was able to solve this. So, just in case some one else comes here, I found the answer here.

function validateComments() {
//Gets called if the 'OK' dialog button is clicked
//Make sure dialog comments are not empty
var comments = gel("dial_comments").value;
comments = trim(comments);
if (comments == "") {
//If comments are empty stop submission
alert("Please provide comments to submit the dialog.");
return false;
}

I had no luck grabbing the element using "getElementById" and so I tried this. It didn't work until I add the "trim" part.

 

Good luck.