Copy link to clipboard
Copied
I have a javascript running that depending on a drop list selection fills from 2 to 16 fields. Upon another list selection it resets all 16 fields and then repopulats with the new data. The problem I am having is if I try an type input into the form manually in one of the fields.....it deletes as soon as the data is commited ie I hit enter. I was using a do while loop do erase the fieds and the stop(used a for loop as well) and it still erases the data as soon as you commit the data. As soon as I comment out the this.resetForm([ "" + CountA]) code, the issue goes away, but i end up with any fields not being over written keeping the old data. I've tried using validation, mouse up/down, etc. Gots me stumped.
Copy link to clipboard
Copied
Where did you place the code for populating the fields?
Copy link to clipboard
Copied
It would be helpful if you don't mind sharing your for loop and while loop codes, and also confirm where are you running them from?
For example, from what you're describing looks like a common behavior if the script is run as custom calculation script. But if it is custom keystroke script, then you may be missing something, like for example, "if (!event.willCommit)", event.change, event.changeEx, and also check that the dropdown list menu has set "Commit selected value immediately" (in field Properties -->> "Options" tab) "?
Copy link to clipboard
Copied
Sorry try67, seems like I was typing at the same time as you.
Copy link to clipboard
Copied
I forgot to mention that setting a default blank entry for the dropdown is key when you use the reseForm() function.
In the slide below I added a blank space to the listed item.
Make sure to click on it before you close this dialogue box (I highlighted it in red in my example above) .
When you're working with the field "Properties", whatever entry that you leave selected in your listbox (or comboxes) will become the default value for that list box (or combobox), and it will always display that default value everytime you reset the formfield (or the entire form).
If for some reason this still doesn't work (or is not relevant to your inquiry), I suggest to also include a small line of code as custom calulcation script in the dependent fields, like this:
if (this.getField("myListBox").value =="") event.value ="";
I normally use this with fields that are dependent of a javascript action executed from digital signature fields( for example, a script that executes at signing time from the signature field to push a date value onto another text field).
So, when I clear the signature in the signature field the dependent date field clears automatically.
Copy link to clipboard
Copied
So this is the code I built for the sub total for an hourly time sheet and is running in the the custom calculation script: of the sub-total fields.
var start = this.getField("FROM11").value; // Declare the start time variable GOES UP TO FROM 18
var end = this.getField("TO11").value; // Declare the stop time variable GOES UP TO TO 18
var sub;
var startTime = '11:45 AM' ; //Time for range...NOT CURRENTY USED, CAN'T REMEMBER WHY I MADE THIS VAR
var endTime = '12:15 PM' ; // Stop time for range NOT CURRENTY USED, CAN'T REMEMBER WHY I MADE THIS VAR
var mUnChies = 0
//_____Let's get the numerical day of the week shall we______
var dAyNum = new Date(this.getField("DATE").value);
if (!isNaN(dAyNum.getDay()))
{
switch (d.getDay())
{
case 0:
dAyNum = 0;
break;
case 1:
dAyNum = 1;
break;
case 2:
dAyNum = 2;
break;
case 3:
dAyNum = 3;
break;
case 4:
dAyNum = 4;
break;
case 5:
dAyNum = 5;
break;
case 6:
dAyNum = 6;
break;
default:
dAyNum = ""; // we don't have a valid day
}
}
else
{
dAyNum = "";
}
//_____Got that juicy dataR stored in dAyNum__________________
//__________Now let's make sure we're not crossing over lunch time_____________
if (this.getField("FROM11").value <= '11:45' && this.getField("TO11").value >= '12:15') {
mUnChies = 1
}
// If either of the start or stop variables are 0, return nothing and chill
if (start == "" || end == "") {
this.getField("SUB TOTAL11").value = ""
}
// Else if neither of the start or stop variables are 0 proceed to computation
else {
function diff(start, end) {
start = start.split(":"); //Seperate start hours and minutes
end = end.split(":"); //Seperate end hours and minutes
// Declare computation variables
var startDate = new Date(0, 0, 0, start[0], start[1], 0);
var endDate = new Date(0, 0, 0, end[0], end[1], 0);
var diff = endDate.getTime() - startDate.getTime();
var hours = Math.floor(diff / 1000 / 60 / 60);
// Math things Beep Boop Beep
diff -= hours * 1000 * 60 * 60;
var minutes = Math.floor(diff / 1000 / 60);
//Divide by 60 again to get hour % (Yes I know I could do that as var minutes = Math.floor(diff / 1000 / 60)/60;)
minutes = minutes / 60
if (minutes != 0){ //Check to see if there are any minutes
return hours + minutes;// If there are minute return this
} else {
return hours //If there are NO minute return this
}
}
sub = diff(start, end);
//_________________________________________________________________________________
// Use this part of the code when back on 8hr days to deduct lunch time crossovers
if (dAyNum > 0 && dAyNum < 6 && mUnChies == 1) {
sub = sub - .5
}//_____________________________________________________________________________________
if (sub < 0) {
sub = sub + 24 //Dirty little statement to fix the pesky 24H day setting
}
this.getField("SUB TOTAL11").value = sub;// Output this to SUB TOTAL
}
Works great and I'll clean it up later.... my seperate drop down list box fills in the hours automatically in the hh:mm format for the above code to analize. I have the "Commit selected value immediately" box checked and in the validated selection of the drop down list box I am trying to run this code so it exectues 1 time each time the list selection changes....but it's not working.
for (var i = 1; i < 9; i++){
this.resetForm(["FROM1" + i , "TO1" + i , "SUB TOTAL1" + i ])
}
if (this.getField("PM's").value == "1 PM"){
this.getField("FROM11").value = "07:45"
this.getField("TO11").value = "16:15"
}
if (this.getField("PM's").value == "2 PM's"){
this.getField("FROM11").value = "07:45"
this.getField("TO11").value = "11:45"
this.getField("FROM12").value = "12:15"
this.getField("TO12").value = "16:15"
}// THIS IS JUST A SMALL TEST CODE TO GET THE DANG THING TO WORK
Just inputs the field randomly"yes I know it's not actually random"lol and doesn't reset the fields.....now if I run it from the custom calculation script: of said list box it works perfect but won't let me manually input times...it just erases them after I enter them. I need to be able to let the list box fill these time fields AND be able to manually fill them
I hope this helps.... I've only been ussing java syntax for about 3 weeks. my background is excel formulas and VBA so I'm still learning the java library, and I'm sure it shows from my pumpkin spice code, any help would be greatly appreciated.
Copy link to clipboard
Copied
This kind of statement is not going to work:
if (this.getField("FROM11").value <= '11:45')
You can't use mathematical operators on a time string and expect it to work...
Copy link to clipboard
Copied
That part seems to works just fine. If it's a weekday and the from/to times cross 11:45 to 12:15 it automatically deducts .5 hours from the subtotal; Saturday and Sunday it doesn't subract .5 hgours from the total. The part that doesn't work is the second code trying to reset the fields fter the list selection changes.
Copy link to clipboard
Copied
Have you check if the failure on resetting the fields may be realted to field calculation order?
Copy link to clipboard
Copied
I doesn't matter where it iterates, I get the same outcome. If i could find a way for it to only execute once in the custom calculation script: and stop it would probably work just fine, but every keystroke the loop reiterates and deletes any find i populate manually. It's supposed to work in validate field codes, but it just partially executes and then gets all buggy. I'm currenty trying to make somekind of call to function that will halt the loop after one cycle.
Copy link to clipboard
Copied
UPDATE: So apparently it's not the code, but the drop down list. After some research these fields execute way different than other fields. Long story short it works just fine with a regular text field, I'll only allow validate entries instead of picking from a list....
Copy link to clipboard
Copied
UPDATE: Got it to work with a list...apparently lists don't like this.getField..value when referencing itself but loves event.value. Thank yuou guys for all the replies.
Copy link to clipboard
Copied
No, that's not it. It's just that in the event you used (Validate, most likely) the value has not yet been applied to the field (as it's still being validated), so accessing it via getField("...").value will return the field's current (ie. old) value, not the new one.