refreshFormTracking for capturing dynamic form changes

Hello has anyone tried to tackle the issue of refreshing form tracking for newly dynamically added fields in forms? I know it’s supported for links but not forms now. Maybe there’s an elegant workaround that could be employed. Right now, I can think of only to manually attach a custom event to fire change_form for new fields, but that seems a bit messy. Or if it would be possible to reset the formManager state and then calling window.snowplow(‘enableFormTracking’); could work as well, but I’m not sure its possible to do it without fully reloading the tracker.

@evaldas, you can call enableFormTracking again - it is safe to do so multiple times

This will only work for form elements which exist when it is called. If you are creating a form programatically, call enableFormTracking again after adding it to the document to track it. (You can call enableFormTracking multiple times without risk of duplicated events.)

@ihor yes this works for new dynamic forms, but doesn’t work for new fields added to existing forms like when some field is only available after user fills in some text. This is to prevent adding duplicate event listener for submit_form; Ideally you would want to form events and form element events to be handled independently.

Hey @evaldas could you add an issue on the Javascript tracker Repo with a short description and anything you have that would be helpful in reproducing? (eg sample html for a form of the type you’re referring to would be amazing).

I think your suggestion is sensible, it’s not my call whether or not it would be roadmapped/where it would be in the priority list but I think we should track this problem & look into it if the tracker behaves as you describe.

Unfortunately I can’t think of a good workaround for it short of manually instrumenting listeners (which is probably not an easy one), but I’ll mull it over and let you know if I think of something. :slight_smile:

@Colm sure thing, I’ll submit an issue a bit later and thanks for the note :slight_smile: