I'm trying to build a feature into an existing application that performs a custom "validation rule". Normally, this type of thing is accomplished by using Knack's built-in validation, but because the field is an equation field, I've turned to Javascript and jQuery as an alternative.
Essentially, I have a form for a purchase request which includes an estimated price, estimated tax, and estimated shipping. Those fields are summed by an equation field on the form called "Estimated Total".
My goal is to lock the submit button for the form until "Estimated Total" > $20.
To that end, I've created a button called "Check Total" which the user theoretically clicks after inputting their estimated prices. Then, my code should execute and unlock the submit button.
However, I keep getting errors in the console from my custom code and I'm too inexperienced to know what I'm doing wrong. This is my code so far:
//Connor Code
$(document).on('knack-scene-render.scene_387', function(event, view, data, scene) { //select the scene view on which to execute
Double check the selectors are correct, but it might be because you are reassigning the variable on this line:
if ((totalCalc = 20)) {
When you should be using an equality operator ===. In JavaScript one equals = means you want to assign the variable, and 3 equals means you want to compare them.
Thank you very much Kelson - that was causing the errors that were preventing the custom script from running.
Now it is running, but I'm still having trouble with the code. It looks like my IF statements regarding the button are not actually firing when the button is clicked. Any thoughts? I appreciate the time you've put into this already.