Re: Form fill - overwrite fields when the values are blank

Håkon_Rød
Level 2

Form fill - overwrite fields when the values are blank

In some forms we want the open text field to be overwritten when the values are blank.

How can we achieve that?

7 REPLIES 7
Jay_Jiang
Level 10

Re: Form fill - overwrite fields when the values are blank

with some mktoForm js you could change the field values to be "NULL" on submit if the field value is empty

Vinay_Kumar
Level 9 - Community Advisor

Re: Form fill - overwrite fields when the values are blank

To achieve this:

you can set default values.

or 

you can use JS

SanfordWhiteman
Level 10 - Community Moderator

Re: Form fill - overwrite fields when the values are blank

The problem with simply setting the value to NULL using JS (and it's even more obvious if you set a default value) is the user sees the word NULL, which looks unprofessional IMO.

 

I have a blog post coming out next week where I show how to set the value to NULL while the field still looks empty to the end user (and no, it doesn't use a hidden field!).

 

In other words, instead of this confusing experience:

Video_2021-03-02_170023_lc.gif

 

 

This smoother one:

Video_2021-03-02_170240_lc.gif

 

Jay_Jiang
Level 10

Re: Form fill - overwrite fields when the values are blank

Ah yes, I admit I forgot that the form field is still visible for a split second when you change values that way.

 

I would then probably just use js to add hidden fields for the fields that are empty and set the values of those to NULL. It might be hacky but I think it should work.

SanfordWhiteman
Level 10 - Community Moderator

Re: Form fill - overwrite fields when the values are blank

That'll work fine, though requires a proxy for every field that might be blank-able. I think you'll like my technique when it comes out.
Anne_Sample
Level 2

Re: Form fill - overwrite fields when the values are blank

@SanfordWhiteman - do you have a link to the article with this trick in it? 

Anne Sample
SanfordWhiteman
Level 10 - Community Moderator

Re: Form fill - overwrite fields when the values are blank

There isn’t a post dedicated to it (too backed up still with other posts) but you can see it in action here:

MktoForms2 :: Referral v2.0.2

 

The method is part of the FormsPlus::Core 1.0.8 JS library (loaded in the HTML pane). It’s called FormsPlus.util.Forms.freezeInput and it takes 3 arguments: a Marketo form object, a field name, and the value to visually “freeze” at:

FormsPlus.util.Forms.freezeInput(mktoForm,systemMktoFields.email,initialValues[instanceMktoFields.lastReferralEmailAddress]);
FormsPlus.util.Forms.freezeInput(mktoForm,instanceMktoFields.lastReferralEmailAddress,"");