Relative Date Validation | Community
Skip to main content
Answered

Relative Date Validation

  • February 16, 2021
  • 6 replies
  • 1408 views

Relative Date Validation

I’d like to be able to validate the answer to a Date Question, so that only the following is accepted:

  • Current or next week
  • Excluding ‘today’ and ‘tomorrow’
  • Excluding weekends, so Saturday and Sunday

In other words, where today is ‘t’, t+2 to t+14 excl. weekends. All other dates would then be routed to an ‘error’ page. Any tips or tricks to help me out here?

 

P.S. I know that I could manually update a Typeform daily, but that creates an excessive amount of work and a high risk of manual error.

Best answer by picsoung

Logic and dates is definitively a hard subject.
But we recently implemented ways to compare dates in the Logic panel.
Here is an example.


Sadly this currently only works with constant dates, and not dynamically yet with things like today, tomorrow


But if you are up for an adventure there might be a workaround using our APIs :)

Those logic jumps are defined in the logic part of your form definition, available on https://api.typeform.com/forms/YOUR_FORM_ID


And they look like this

{
	"action": "jump",
	"details": {
		"to": {
			"type": "field",
			"value": "ID_OF_FIELD_WHERE_TO_JUMP"
		}
	},
	"condition": {
		"op": "later_than",
		"vars": [{
				"type": "field",
				"value": "ID_OF_FIELD_WITH_DATE"
			},
			{
				"type": "constant",
				"value": "A_DATE_YYYY-MM-DD"
			}
		]
	}
}

Once workaround for now could be to have a script daily that updates the logic jump part of your form with the relevant dates.

You would use the Update Form endpoint of our API.

I built something similar to update dates in a dropdown.

View original

6 replies

Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 14847 replies
  • February 16, 2021

Hi @dan - thanks for stopping by the community! :) While we don’t currently have this feature in our builder, we’ll note this suggestion. :) I’m not sure of any fancy workarounds for this, but possibly @picsoung knows of one!


picsoung
Typeform
Forum|alt.badge.img+5
  • Developer Advocate @ Typeform
  • 384 replies
  • Answer
  • February 17, 2021

Logic and dates is definitively a hard subject.
But we recently implemented ways to compare dates in the Logic panel.
Here is an example.


Sadly this currently only works with constant dates, and not dynamically yet with things like today, tomorrow


But if you are up for an adventure there might be a workaround using our APIs :)

Those logic jumps are defined in the logic part of your form definition, available on https://api.typeform.com/forms/YOUR_FORM_ID


And they look like this

{
	"action": "jump",
	"details": {
		"to": {
			"type": "field",
			"value": "ID_OF_FIELD_WHERE_TO_JUMP"
		}
	},
	"condition": {
		"op": "later_than",
		"vars": [{
				"type": "field",
				"value": "ID_OF_FIELD_WITH_DATE"
			},
			{
				"type": "constant",
				"value": "A_DATE_YYYY-MM-DD"
			}
		]
	}
}

Once workaround for now could be to have a script daily that updates the logic jump part of your form with the relevant dates.

You would use the Update Form endpoint of our API.

I built something similar to update dates in a dropdown.


Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 14847 replies
  • February 17, 2021

Ooo thank you @picsoung !!


We use typeform for Event Requests within our organization.
We would like to ONLY allow requests that are 4+ weeks out.
Is it possible to have a “calendar/date” question that DOES NOT allow the date to be selected within a certain time frame?

 

Thanks!


Mariana
Ex–Typefomer
Forum|alt.badge.img+5
  • Ex–Typefomer
  • 679 replies
  • April 14, 2021

Hi @fallonmichaeltx. Happy Wednesday :hugging:

 

I moved your question to this conversation so you can check the thread and the workaround suggested here 🙂 Hope this helps! 


  • Navigating the Land
  • 2 replies
  • July 16, 2021

Hi, I’m new to Typeform and wondering if there’s a way for clients to choose a date to book a birthday party slot and then make that date unavailable to other form users once all slots that day are filled. 

Understand this might not be do-able but wanted to check! Thank you 


Reply