Curious how I'd do this:
Let's say I have a form with a hidden field of Country, which on the form defaults to United States. The code to embed and run the form is on my LP template. The correct form is chosen by a token so I don't know whether or not I'll be asking the Country question.
If the lead is known and has a lead.Country value, I'd like to defaul to that value. If the lead is unknown, I'd like to default to United States. How do I modify my form.vals() in the code to choose the default option on the form itself? Some forms using this template might be Canadian and I may want to default them there instead of United States.
Will the Country be originally entered by the lead in that same browser? If so, save it to localStorage onSuccess, then fetch it out in a subsequent form's whenReady. (You could use cookies, but localStorage is way easier unless you absolutely need to share across a parent domain.)
No clue. And I don't know that I'll be giving them the opportunity to enter it. I also can't guarantee that other people will remember to put Country on their forms, so it's also possible that a lead could be created without a country code.
I'm starting to think that putting the form on the field is the only option.
Sounds like the "self-hiding field" pattern: a field that's hidden if it has a value, shown if empty.
There's a demo here: MktoForms2 :: Self-Hiding Field
In the demo, the fields Country and LastName are both set to self-hide. If they have previously filled values, their form widgets will not be shown.
Is a default field possible? Can I have like "field":"{{lead.field}}":"DefaultValue"??
Only if you were also using Prefill and/or a Marketo LP, since the token will not be replaced.