I have a task to perform, but after wasting endless hours, I am finally about to give up on doing something that should be brain-dead simple. Here's what I want to do.
I have a form that is connected to a collection called "Referrals" and there are various UserInput fields that are connected to respective columns in the collection. All that works just fine, but what I want to do is to have the user enter a code. The code is associated with a person whose first name, last name, and company name are defined in another collection called "Salespersons". When the user enters a code, let's say "XYZ", in a UserInput field (#input1), the code in the input1_blur event should extract the value entered into that field (#input1), look up that value in the Salespersons collection, return a result array, and then place the values for the first_Name, last_Name, and company_Name columns into text fields (not UserInput fields) that are placed adjacent to the UserInput field. The purpose of this is to allow the user to see that the code he or she entered is the code for the correct person before proceeding to do additional input on the form.
I have tried endless combinations with .find, .get, and who knows what else is out there, but the issue seems to be these:
1. I cannot seem to log any results from the blur event in the console screen.
2. Nothing changes in the text fields after I leave the UserInput field, suggesting to me that I may be using the wrong event to begin with or that text fields cannot be updated after the page has been rendered.
So, how do I make this work? I want the text fields that will display the looked up first, last, and company names to be uneditable by the end user.
I will gratefully accept a workable answer no matter how arcane.
Thank you. The code worked with minor fixes. One thing that confused me was whether to use a column's name or a column's key name. The two can be different, and there seems to be an assumption that the developer knows that the key name is to be used without having to be told explicitly.
One more question I have revolves around how to send out an email from the server programmatically. I can always link to the client's email software by using mailto:, but I would like to be able to have the server send out an email to me when someone fills in a custom form successfully. Are you aware of any code examples that show how to do this?
Thanks again!
something like this...
import wixData from 'wix-data'; $w.onReady(function () {
$w('#input1').onChange((event) => { let userInput = $w('#input1').value; //Salespersons is the name of your database, change as necessary wixData.query("Salespersons") //change yourColumnFieldKey to whatever field key you are using in your database .eq("yourColumnFieldKey", (userInput)) .limit(1) .find() .then((results) => { let searchResults = results; console.log(searchResults); let firstName = searchResults.first_Name; let lastName = searchResults.last_Name; let company = searchResults.company_Name; //set the on screen text $w('#text1').text = firstName $w('#text2').text = lastName $w('#text3').text = company }) }) })