Copy link to clipboard
Copied
Hello,
i have a code which works, but the console gives me an error anyway.
Can i ignore that because of the functionality is given or not?
I know i bet there is a better way to code this with javascript but it works fine and its with my current javascipt abilities 😉
if (this.getField("orderType").value == "abc") {
if (this.getField("qtyBase").value < 1 || this.getField("qtyBase").value > 1) {
this.getField("qtyBase").value = 1;
}
else {
this.getField("qtyBase").value = "";
}
}
else {
this.getField("qtyBase").value = "";
}
if (this.getField("qtyBase").value < 1) {
this.getField("qtyBase").value = "";
}
Console:
InvalidSetError: Set not possible, invalid or unknown.
Field.value:3:AcroForm:qtyBase:Calculate
Additional, is there a possibility to run a code when leaving the field?
I would like to check this condition also after typing. Now it gets fired after the next change in the document.
Many Greets
Copy link to clipboard
Copied
No, you should not ignore error messages...
Are you trying to manually enter a value into this field? That's might be causing this error.
Also, you should replace all instances of:
this.getField("qtyBase").value = ...
With:
event.value = ...
The calculate event will trigger each time the value of any field in the file is changed. Is that not sufficient?
Copy link to clipboard
Copied
Thank you very much for your answer.
Yes, this field is a quantity-field. The user should be able to enter the quantity.
The code should create presets of previous choices and deleting "0" to "".
if i type "event.value" is this code also triggered if another field changes the field with the event?
The calculate event will trigger each time the value of any field in the file is changed. Is that not sufficient?
I want to input alerts if the input is not matching my requirements and this should be better when directly leave the field than when the user is at the next field in his mind. Additional removing the "0" would be better instantly instead of later but that is cosmetic.
Copy link to clipboard
Copied
To have a field both accept manually entered values and have a calculated value requires defining clearly when each one should take preference, and then using specific code to allow for it. You can't just do both and expect it to work correctly, as they conflict with one another.
Copy link to clipboard
Copied
Would it be possible to put the code in the custom validation code instead?
Dont know how to tell the field exactly this value is correct and this not.
And if a radio bottom in form is changed delete your value for example.
You understand what i mean?