User input to reference existing database

Hi,

Have been using Wix for just over a year or so for a band website and am after a bit of help with my first Wix Code idea…

So, there will be 2 elements to this:

  1. A list of upcoming events, which is linked to the ‘Events’ database
  2. A user-input page used for booking queries and gather the data within the ‘Enquiries’ database

What I’m trying to do is get the date picker to query the ‘Events’ database and return a message of some sort to let the client know that date is unavailable if an entry already exists on that date within the ‘Events’ database. Ideally only if the event on that date, already contained within the ‘Events’ database, had a certain word in another field.

      *Example: 25th December 2018 is selected from the date picker -> 'Events' database is queried -> query searches for a row that contains  [u]both[/u]  '25/12/18' in the date column AND 'Private' in the type of event column. Expected result in this case would be to return "We are very sorry but we appear busy on your selected date". 

If the date selected in the date picker does not match a row that contains both the selected date (from the date column) AND the word ‘Private’ (from the type of event column) then no message is displayed and the user-input is submitted into the ‘Enquiries’ database.

Sorry if this has already been covered somewhere else on the forum already!

Thanks in advance.

Matt

Hello Matt,

Start by creating both ‘events’ and ‘enquiries’ databases and the enquiry form.
Adding the logic should be done using code.
Your enquiry form should get the selected date from the datepicker and query the events collection according to the logic you have described.

I have created a basic code skeleton which should get you started:

import wixData from 'wix-data';
export function submit_click() { //user clicks the submit button	
	const selectedDate = $w('#dateInput').value; //gets the selected 
	wixData.query("events")
		//filter eventType = private	
		.eq("eventType","private")
		//filter the selected dates
		.eq("date", selectedDate)
		.find()
		.then((results) => {
			//do something with results
		})
		.catch((err) => {
			let errorMsg = err;
		});
}
});

One more suggestion - try to first get the available dates and display them instead of letting the user resubmit the form each time a date is already taken.

More information regarding wixData query can be found here

Good luck!

Hey Ido,

Thanks for your quick response, i’ll give that a go and let you know how I get on :slight_smile:

Cheers!