Re: How to show the number of "This field is required" in Marketo forms

zhyl
Level 1

How to show the number of "This field is required" in Marketo forms

As it works today, if you miss to fill out a required field you will see “This field is required”. If you miss to fill in several fields you will still see “This field is required” one field at the time. 

 

Would it be possible to show the number of fields that is required as a complement to how it is today? For example if I have not filled in any form and press Download/ Submit button, it should appear a text that says “7 fields are required”.

 

Thanks!

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: How to show the number of "This field is required" in Marketo forms

“7 fields are required” I‘d think.

 

You can get the number of (natively) invalid fields and do whatever you want with it:

MktoForms2.whenReady(function(mktoForm){
   let formEl = mktoForm.getFormElem()[0];
   
   mktoForm.onValidate(function(nativeValid){
      if(!nativeValid){
         let numInvalids = formEl.querySelectorAll(".mktoRequired.mktoInvalid").length;
         // do something with numInvalids
      }
   });
});
Jo_Pitts1
Level 10 - Community Advisor

Re: How to show the number of "This field is required" in Marketo forms

With some special case coding for "1 field is required" (no s on fields and is not are)

Cheers

Jo