Forums

date validate

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
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
Colnem 10 Mar, 2022
Hi

try {data:-18y}
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.
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
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
You need to login to be able to post a reply.