Auto-Populate Form Fields
The auto-fill functionality allows you to auto-populate form fields of your surveys with previously entered data. This functionality is useful when part of survey information is already known. For example, Name and Email form fields can be filled automatically based on user login information.
To pre-populate form fields, use the data
property of a Survey instance. This property contains survey result data as an object in which keys are question names and values are answers. To manage the survey result data, assign a new object to the data
property. You can define this object locally or load it from a web service. In this demo, the data
object is used to pre-fill information in read-only form fields.
Note that a new data
object replaces the old object and erases entered data if there was any. If you want to merge the new and old objects, call the mergeData(newDataObj)
method.
If you want to pass values into individual form fields, call the setValue(questionName, newValue)
method. Open the Settings panel and enter a value into one of the text boxes there. You will see this value copied into the corresponding question. This happens because the text boxes call the setValue
method to auto-populate survey questions dynamically. A Survey instance also has the getValue(questionName)
method that allows you to access individual form field values at runtime. Note that if you need to set more than one form field, replace the data
object or call the mergeData(newDataObj)
method to ensure optimal performance.