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!
Code I am using:
<script>
MktoForms2.whenReady(function(form){
form.setValues({
IsAgencyDynamic : form.getValues().IsAgency
});
})
</script>
Solved! Go to Solution.
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);
});
The field name is isAgency (no initial cap).
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!
Marketo forms checkboxes use "yes" or "no" (case sensitive) not True/False
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?
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.
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:
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?
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.
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>
You want
yes|yes
no|no