Page 1 of 1

Condition to detect whether a Suggest control has found something

Posted: Wed May 03, 2017 3:52 am
by shuqierduo
A suggest control "customerName" which the underlining sql is simply selecting customer_id and customer_name from MySQL

For the moment I am using the following logic to detect whether something is found from the database and I am curious on how the others do it with PM?
Code: Select all
if ($("#customerName").getValue() == $("#customerName").getText()) {
// code for result NOT found
} else {
// code for result found
}

Re: Condition to detect whether a Suggest control has found something

Posted: Wed May 03, 2017 4:45 am
by mishika
Hello,

Could you please elaborate the issue you are facing?
Why is it that you are comparing ($("#customerName").getValue() == $("#customerName").getText()) ? Can you explain what check do you want to make here?
What is the SQL query you have used?

Best Regards
Mishika

Re: Condition to detect whether a Suggest control has found something

Posted: Wed May 03, 2017 1:35 pm
by shuqierduo
Sorry for the confusion. The query is simply "SELECT CUSTOMER_ID, CUSTOMER_NAME FROM CUSTOMER"

Let's say the table "CUSTOMER" contains records below

CUSTOMER_ID, CUSTOMER_NAME
1, 'Steve'
2, 'Mary'
3, 'John'

Name of the Suggest control is customerName

If user input and select 'Steve' on the control $("#customerName").getValue() will return 1 and $("#customerName").getText() returns 'Steve', meaning that the two does not matches.

However, if I input 'Nicholas', both $("#customerName").getValue() and $("#customerName").getText() return 'Nicholas'

nothing will be found and below condition if ($("#customerName").getValue() == $("#customerName").getText()) { will be fullfilled

Re: Condition to detect whether a Suggest control has found something

Posted: Wed May 03, 2017 10:14 pm
by amosbatto
shuqierduo,
Your method is probably the easiest way to do it. Another way is to use control.executeQuery() to get the list of options for the suggest box and then search in the list to see if the current value of the suggest box is in the list of options.