How to set dates in the search form

The article provides an example of setting up a full search form for flights (Aviasales) so that the date of departure and return is preset in it.

In a short search form the departure date is usually equal to the current date (unless you changed it in the settings). At the same time, in the full search form, the date fields are empty by default. You can fix this by replacing depart_date and return_date with the following code:

 "depart_date": new Date().toISOString().slice(0, 10),
 "return_date": new Date(new Date().getTime()+(7*24*60*60*1000)).toISOString().slice(0, 10),

In this case the departure date will equivalent to the current date. And the date of return plus seven days.

Sample of search form:

Was this article helpful?

Have more questions? Submit a request