date validate

How to show or hide a multifield based on a date being over 18 years ago.

Overview

The issue is needing to conditionally display a form field when a user's entered date indicates they are at least 18 years old.
Use a custom JavaScript validation rule on the date field. The function calculates the age from the entered date and shows or hides the target multifield by its ID.

Answered
ChronoForms v7
Ja Javierflk 09 Mar, 2022
Hello
How can I show or hide a multifield if when entering a date more than 18 years have passed
thank you
Gr GreyHead 10 Mar, 2022
Hi Javierfik,

I think that the only way to do this is to use a custom JavaScript function that is triggered when the date field changes.

Bob
Ja Javierflk 11 Mar, 2022
Thanks for the answers and sorry for my ignorance.
The trigger would be in the datepiker and the javascript too.
As a reference to the multifield from the sctipt?.

another question
Can I generate a pdf without having to submit?

The documentation of chronoforms7 (the videos), do not say anything about this part.

Thank you very much.
Ja Javierflk 12 Mar, 2022
Answer
Hi
i solved it
in calendar field , "validation/custom rule" use this code:
function getEdad(dateString) {
let hoy = new Date()
let fechaNacimiento = new Date(dateString)
let edad = hoy.getFullYear() - fechaNacimiento.getFullYear()
let diferenciaMeses = hoy.getMonth() - fechaNacimiento.getMonth()
if ( diferenciaMeses < 0 || (diferenciaMeses === 0 && hoy.getDate() < fechaNacimiento.getDate())) {
edad--
}
if (edad < 18) {
$("#xxx").show();
} else {
$("#xxx").hide();
$("#text_6").val("");
}
return true;
}
where xxx its the name of the Multi field
we webuniverse 19 Jul, 2022
Hi Javier

I have tried to rebuild your solution, unfortunately without success.

Do you have any printscreens? :-)

that would be great
Corinne
This topic is locked and no more replies can be posted.