Is it possible to validate numeric fields using JavaScript in Next-Gen?

Hi @Quynh-Tram, a lot of us are still wrapping our brains around how to manipulate elements on the page.
One thing I’ve noticed is that Next-Gen has cracked down on changing form input values via JS, so there goes the possibility of updating field values after more complex equations.

If your check is as simple as comparing one number against another, you can get away with this natively:

  1. Add a value difference equation field to your table that gets difference between first and second value:

  2. Add a validation rule to your first value field that checks the value difference field:

  3. Add this equation field to your form:


    You can optionally hide it with CSS using something like:

    .kn-input.field_xx {
      display: none;
    }
    
    
  4. When you submit the form, the native validation should run:

Note that this won’t work if your equation is too complex for Knack to process live in the form, and likely won’t work when doing inline-editing in grid views.

Let me know if that works for you?

1 Like