SOLVED

Re: Forms 2.0 API and Visibility rules. Bug or expected behavior?

Go to solution
Grégoire_Miche2
Level 10

Forms 2.0 API and Visibility rules. Bug or expected behavior?

Hi all,

We have observed a quite annoying behaviour on the forms API when you combine it with some visibility rules.

A form contains an Opt-in field (Name BEU_SOI) and an OptIN Date field (Named BEU_SOI_DateTime). The BEU_SOI Field has a visibility rule and is controlled by the BEU_SOI_DateTime field: BEU_SOI only shows if BEU_SOI_DateTime is empty.

That Forms also has a script that handles some information directly in the form. Namely, if the BEU_SOI is checked, BEU_SOI_DateTime is filled with the current datetime. What is really weird is that in this case, the BEU_SOI is simply removed from the values sent to Marketo! It seems to be related to the visibility rule as if we remove the visibility rule, the problem disappears.

Test it here: https://m.konicaminolta.co.uk/SOI-tests.html?aliId=50831173

Is this a bug or an expected behavior ? If the later is true, what am I missing ?

Thx for your help

-Greg

Justin CoopermanSanford Whiteman

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Forms 2.0 API and Visibility rules. Bug or expected behavior?

Check this demo and pay very close attention to the order of operations:

MktoForms2 :: Set VR-hidden Field

Network trace:

pastedImage_0.png

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Forms 2.0 API and Visibility rules. Bug on expected behavior?

Yes, this is expected behavior -- at least once you settle on a working definition of how Visibility Rules work.

A call to setValues() triggers VRs -- which is a good thing -- even if it's done in an onSubmit listener. (Remember, a given listener doesn't know if it's the last listener in a stack of listeners, so it may not be past the point of user interaction, i.e. if a later listener sets the form to submittable(no) then the form remains usable.)

So you're removing the checkbox from the form entirely when setting the date.

To compensate for this, set the checkbox value with addHiddenFields, not setValues. (I don't recommend using the alias vals as it obscures this important difference.)

Grégoire_Miche2
Level 10

Re: Forms 2.0 API and Visibility rules. Bug or expected behavior?

Hi Sanford,

Thx for looking into it.

I tried with addHiddenfFields before, with the same result Then I tried with the setValues with the hope that it would change something, but...

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Forms 2.0 API and Visibility rules. Bug or expected behavior?

Are you sure you had the timing right with addHiddenFields?  Your code is on that page is... rather verbose. Could use some refactoring before you debug this particular issue.

SanfordWhiteman
Level 10 - Community Moderator

Re: Forms 2.0 API and Visibility rules. Bug or expected behavior?

Check this demo and pay very close attention to the order of operations:

MktoForms2 :: Set VR-hidden Field

Network trace:

pastedImage_0.png

Grégoire_Miche2
Level 10

Re: Forms 2.0 API and Visibility rules. Bug or expected behavior?

Hi again Sandy,

Thx for the hint about the order of operations. The fixed it!

-Greg