formstack

Input Field Value Resetting on Form Submission Issue


I'm working on a form where I need to set an input field value using JavaScript. The input is hidden initially, and I set its value with JS code. However, the value gets cleared just before the form is submitted.

Here are the steps I took and the issues I'm facing:

When I load the form, the value is set correctly if the input is visible. The value gets cleared when I click on the input. I suspect this clearing behavior is causing the issue. I've also tried firing events to mimic user input, but it didn't work. Here is the JS code I'm using to set the field value:

var newValue = 'code-calculate-value';
var field = document.getElementById('field123456789');
field.value = newValue;

Is there any alternative method to retain the value upon submission, or do I need to make specific changes in the new FormStack settings? Any suggestions on how to resolve this issue would be greatly appreciated.


Solution

  • I was able to resolve it, Formstack uses the new Forms builder API v4, which have breaking changes, so to access the field I had to use the FormAPI, for more details here is the API specifications: https://live-form-api.formstack.com/index.html

    to get the field:

    var form = window.fsApi().getForm("100");
    
    var dataField = form.getField("12345");
    dataField.setValue({value:'new value'});