I’m trying to develop a script for Flokzu (A BPMN software that uses js scripts to define form field validations) and i’m asked to validate vacation days request fields. E.g. start date is after today and before end date. So far it works as long as the end date is within the same month; as soon as the end date is a different month, the if block kicks in. This is the code i’ve come up with so far, with corresponding translation:
- [[Fecha de salida]] = Departure Date (field filled in the form from a calendar dropdown and grabbed by the script)
- [[Fecha de regreso]] = Return Date (field filled in the form from a calendar dropdown and grabbed by the script)
- Flokzu.onChange() = platform specific function that executes the function when the listened field changes its value in the form
function Fechas(accion){
if(accion){
return moment(Flokzu.getFieldValue( [[Fecha de salida]]),
"YYYY/MM/DD")
}else{
return moment(Flokzu.getFieldValue( [[Fecha de regreso]]),
"YYYY/MM/DD")
}
}
function ValidarFechas(msg, boton) {
var Salida= Fechas(true), Regreso= Fechas(false), today = moment();
// Check if Salida is before today or after Regreso
if (Salida.isSameOrBefore(today) || Salida.isAfter(Regreso)) {
swal({
type: 'error',
title: 'Error en las fechas!',
text: 'La fecha de salida debe ser posterior al día de hoy y anterior o igual a la fecha de regreso'
});
Flokzu.error([[Fecha de salida]], "Cambie a un rango de fechas valido");
}
}
Flokzu.onChange([[Fecha de regreso]], ValidarFechas);
If, for example, I evaluate with values:
- Departure = 2024/05/27
- Return = 2024/05/31
- Today = 2024/05/26 (selected automatically from the “moment()” function
It works as intended
But if i select
- Departure = 2024/05/27
- Return = 2024/06/01
- Today = 2024/05/26 (selected automatically from the “moment()” function
It displays the error.
Any idea why? How could i solve this?
Unfortunately I cannot log form outputs since the implementation of scripts is kind of raw and only lets me write the script in a pop up text field and save it. Then I need to run the process and simulate some form fill outs to check for errors so I’m not sure if I’m grabbing the dates in a correct format. Thanks in advance