SOLVED

Re: Using lead form values to dictate form field visibility rules

Go to solution
Jimmy_Forde
Level 2

Using lead form values to dictate form field visibility rules

Hello! 

I am trying to make a form field visible only if there is a null value for another field in our instance. I have tried to implement using this thread: Form field conditional on current vlaue. However when I test it doesn't seem to work, the form value that I am trying to hide/show ( IS Agency) keeps showing no matter what. 

The form I am trying to do this for has Is agency as the field with visibility rules, based on a hidden field that is "IsAgencyDynamic". Prefill is enabled for both fields, and Is Agency has the below visibility rules. I have implemented this JS and form on this landing page.  Can you help me identify why this is not working? Thanks!

pastedImage_2.png

Code I am using: 

<script>
MktoForms2.whenReady(function(form){
form.setValues({
IsAgencyDynamic : form.getValues().IsAgency
});
})
</script> ‍‍‍‍‍‍‍‍‍‍‍‍‍‍
1 ACCEPTED SOLUTION

Accepted Solutions
Jay_Jiang
Level 10

Re: Using lead form values to dictate form field visibility rules

try this:

MktoForms2.whenReady(function (form) {
var init_fields = {
"isAgencyDynamic":"{{lead.Is Agency}}", // whatever your Marketo token is supposed to be
}
form.vals(init_fields);
});

View solution in original post

18 REPLIES 18
SanfordWhiteman
Level 10 - Community Moderator

Re: Using lead form values to dictate form field visibility rules

The field name is isAgency (no initial cap).

Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Thanks! I was using the import alias instead of what was represented as the name in source code. It looks like both fields have the first i lowercase. 

I made those adjustments and the form is still not working..Any other suggestions? Thanks!

Jay_Jiang
Level 10

Re: Using lead form values to dictate form field visibility rules

Marketo forms checkboxes use "yes" or "no" (case sensitive) not True/False

Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Thanks! I edited the form, the checkboxes to yes/no values with the stored value being true/false. Are you saying that I should change the visibility rules to yes and no instead of true and false? I tried it that way as well, and it still didn't work.

Any other suggestions? Below is what my visibility rules are set at now ( I tried both yes/no value and the true false value, as I wasnt sure if it is looking for the picklist value or the stored value), I have the JS on the page as well. Would it make more sense to just do if isagencydynamic is null then show, rather than the below?

pastedImage_1.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Using lead form values to dictate form field visibility rules

You have to be very careful with letter case here.

The strings "yes" and "no", all lower case, are accepted as aliases for Boolean fields. 

The strings "Yes" and "No", with the first letter capitalized, are also accepted.

The strings "true" and "false", all lower case, are also accepted, because those are the direct stringified equivalents of the reserved words (no quotes) true and false.

But the strings "True" and "False" with the first letter cap'd are not.

Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Got it, that makes sense. I want to Keep true/false as the stored values to be consistent with what we already have in our database, but yes/no makes more sense for someone filling out the form. Everything is edited to the capitalization requirements ( see below) and the form visibility rules still don't seem to be working. Any other suggestions? Thanks!

Values:

pastedImage_2.png

Visibility Settings: Also tried it with just yes and no instead of true, false. Neither worked. Would it work better if I just said "Show" if isagency dynamic is "null"? That's basically what I am trying to accomplish, just don't know if putting "null" would work, or can i just leave the value blank?

pastedImage_1.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Using lead form values to dictate form field visibility rules

I want to Keep true/false as the stored values

You don't have to worry about that. As a Boolean field in the Marketo database, its stored values are always Boolean true and Boolean false (not strings).

On the front end (form end) is where you need to tightly manage your form values vs. the Visibility Rules that consult those values.

Jimmy_Forde
Level 2

Re: Using lead form values to dictate form field visibility rules

Got it, makes sense!

So then this visibility rule should then work right, since the js below should be updating the isagencydynamic field to be yes or no? Still for some reason is not working for me.

Code I have on page: https://build.amazonalexadev.com/Youtube-Integration_DynamicTest.html 

   <script>
MktoForms2.whenReady(function(form){
form.setValues({
isAgencyDynamic : form.getValues().isAgency
});
})
</script>

pastedImage_1.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Using lead form values to dictate form field visibility rules

You want

   yes|yes

   no|no