Detect field value change in adaptive forms | Community
Skip to main content
Level 4
Nov 22, 2021 7:24 PM UTC
Solved

Detect field value change in adaptive forms

Hello,

 

Is there a way to determine if the value of a field has been changed in an adaptive HTML form other than having a hidden field with the initial value in it that gets compared when the Value Commit event is triggered?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
radzmar
radzmarAccepted solution
Level 10
Nov 22, 2021 8:43 PM UTC

Hi, you can add event listeners to various events. As an example: This script in the initialize event of the guide root panel will cause, that every change in your form is reported into the console of the web browser.

 

guideBridge.on("elementValueChanged" , function(event, payload) {
     console.log("The value of object '" + payload.target.name + "' has been changed from '" + payload.oldText + "' into '" + payload.newText + "'.");
});

9 replies

Mayank_Gandhi
Employee
Dec 1, 2021 8:44 AM UTC

@seanlapointe  You can go with what @radzmar  suggested or you can create custom listener as well. 

 

const input = document.querySelector('input');
const log = document.getElementById('yourFieldID');

input.addEventListener('change', updateValue);

function updateValue(e) {
  log.textContent = e.target.value;
}
Translate
Mayank_Tiwari
Employee
Nov 23, 2021 7:55 AM UTC

Use this:

 

Translate
Pulkit_Jain_
Employee
Nov 22, 2021 8:44 PM UTC

@seanlapointe 

Usually button clicks or field exit events can be used to validate the rules so you can check for the  (field value change AND value of the field against the set default value of the hidden field) here.

 

Translate
radzmar
radzmarAccepted solution
Level 10
Nov 22, 2021 8:43 PM UTC

Hi, you can add event listeners to various events. As an example: This script in the initialize event of the guide root panel will cause, that every change in your form is reported into the console of the web browser.

 

guideBridge.on("elementValueChanged" , function(event, payload) {
     console.log("The value of object '" + payload.target.name + "' has been changed from '" + payload.oldText + "' into '" + payload.newText + "'.");
});
Translate
Level 4
Nov 23, 2021 3:11 PM UTC

payload.oldText returns 'undefined' for every change. I was trying to avoid using hidden fields, but I guess I don't have much of a choice. 

Translate
Level 4
Nov 23, 2021 6:39 PM UTC

I was able to set some variables for the original values in the guide panel init that persisted when the event fired. This works great, thanks!

Translate