Repeat Field Validation
I am trying to validate a date field within a repeating section(table). So far I am only getting a "Mixed spaces and tabs" error within the rules editor. I am thinking I must be doing something wrong with my code. Below is my code for the repeat...
var today = frevvo.currentDate().split('-');
var today_date = new Date(today[0], today[1]-1, today[2]);
for (var i = 0; i < EventDate.value.length; i++) {
var sd = EventDate[i].value.split('-');
var ed = EndDate[i].value.split('-');
var sd_date = new Date(sd[0],sd[1]-1,sd[2]);
var ed_date = new Date(ed[0],ed[1]-1,ed[2]);
if (sd_date < today_date || ed_date < today_date) {
if (sd_date < today_date) {
EventDate[i].valid = false;
} else {
EventDate[i].valid = true;
}
if (ed_date < today_date) {
EndDate[i].valid = false;
} else {
EndDate[i].valid = true;
}
} else {
EventDate[i].valid = true;
EndDate[i].valid = true;
}
}
Any help you can provide would be appreciated...thanks,
Suzanne
-
Official comment
Hi Suzanne,
In the rule editor, which lines are giving you the error of mixed tabs and spaces?
Thank you,
Courtney
-
Hi Courtney,
The errors change when I login and out. Currently the error message is as follows...
----------
Line 15, character 4: EventDate[i].status = "Invalid Date. Please only submit future events.";
Mixed spaces and tabs.
---------
Although the code still seems to be working even with the errors showing up. Yesterday it listed even more lines with the same error. And at one point yesterday the errors went away completely without me changing anything only to come back a few minutes later when I visited the code again. The errors are changing which line they point to, but any line with "EventDate[i]" or "EndDate[i] in it, at one point yesterday, showed this error.
I have been having other errors like this for a while now. For instance sometimes it gives me an error using the field.visible or field.required, etc... saying this is not compatible with javascript (I am paraphrasing because I don't remember the exact language). When these errors show up, my code is correct without errors so I am not sure what is causing it. Again it seems to happen sporadically as well. The code works fine in some forms and not in others.
Maybe it's something to do with our localized setup because I also have trouble editing the form more then once. If I edit the form, save, test and then click on the edit button for the form again, all of the editing windows on the page disappear and I am only shown the form as if it is in test mode. I have to clear the history on my browser every time I edit a form and save. When I clear the history I am asked to login and then I can edit again. As you can imagine this is a bit annoying. :)
Thanks for your help,
Suzanne
0 -
I have updated my code since I first posted as well, to allow for custom error messages. Below is the new code which aligns with the new error message I sent you...
----------------
var today = frevvo.currentDate().split('-');
var today_date = new Date(today[0], today[1], today[2]);for (var i = 0; i < EventDate.value.length; i++) {
var sd = EventDate[i].value.split('-');
var ed = EndDate[i].value.split('-');
var sd_date = new Date(sd[0],sd[1]-2,sd[2]);
var ed_date = new Date(ed[0],ed[1]-2,ed[2]);if (sd_date < today_date || ed_date < today_date) {
if (sd_date < today_date) {
EventDate[i].valid = false;
EventDate[i].status = "Invalid Date. Please only submit future events.";
} else {
EventDate[i].valid = true;
}
if (ed_date < today_date) {
EndDate[i].valid = false;
EndDate[i].status = "Invalid Date. Please only submit future events.";
} else {
EndDate[i].valid = true;
}
} else {
EventDate[i].valid = true;
EndDate[i].valid = true;
}
}0 -
Hi Suzanne,
The mixed tabs and spaces error message is inconvenient. Best to use only spaces to indent. I am going to write a ticket to fix this.
Also, what version of Live Forms are you running?
Best,
Courtney
0 -
Hi Courtney,
I believe we are on 62.
Thanks again for your help,
Suzanne
0
Please sign in to leave a comment.
Comments
5 comments