I'm trying to create a field that automatically fills a date (or whatever value). The formula works but it also locks the value from any changes the user attempts.
I've tryed this:
v1(data, context) {
return new Date();
}
and this:
v1(data, context) {
if (context.cache.alreadyRun) return new Date();
context.cache.alreadyRun = true;
}
but the value always gets locked in the form.
The logic is wrong. Once it has run, it shouldn't return the date any more, but just continue with the existing value. It should be more like this:
v1(data, context) {
if (context.cache.alreadyRun) return data.value;
context.cache.alreadyRun = true;
return new Date();
}
Note that I believe it's still wrong - you probably just want to set the date when it's empty, and not set it again every time the form is opened. So this is probably what you're looking for:
v1(data, context) {
if (data.value) return data.value;
return new Date();
}