I have this situation:
I have a page where I can edit users info(name, email, phone, etc…). when I click on the edit button, it calls a dialog (modal window), that loads the user data that is already set in the database.
When the user click on the Update button, I do a verification in my controller to make sure he inserted a valid e-mail. If the e-mail is not valid, I have an error and I add a class named “error” into the html label, in this specific dialog. What I’m trying to do is, if there’s a mistake, I want the dialog to open right after the verification. As I have this specific class error set only when and where there’s a mistake, so I want your help to find a way to call the dialog $('#addEditUserDialog').dialog('open'); when this condition : $("#addEditUserDialog label.error") happens.
I tried doing:
if ($("#addEditUserDialog label.error")) {
$('#addEditUserDialog').dialog('open');
}
but it’s calling the dialog even if the class error isnot set.
I know it’s a basic question, but I have not much experience with javascript and I’m kind of lost.
A jQuery object is always truthy (that is, it evaluates to true). To test for an element’s existence, one needs to use
$().length(which should be 0 if there are no elements, and will then be false).