I have a use case where I need to add custom attributes to WFFM form fields. I have to add "aria-required" attribute to checkbox field if required is checked for a checkbox field.

I have created another class that inherits from wffm checkbox and have overridden the oninit() method.

protected override void OnInit(EventArgs e)
        var form = WebUtil.GetParent<SimpleForm>(this);
        if (WFFMHelper.IsRequiredField(form, this.ControlName))
            this.checkbox.Attributes.Add("aria-required", "true");

By this the "aria-required" attribute gets added to tag which contains the checkbox. The "aria-required" attribute purpose is lost if added to parent element instead of checkbox.

Please let me know there a way to add custom attributes to checkbox input directly.

Sitecore version 9.0.2 WFFM version 9.0

  • 1
    What version of WFFM and Sitecore are you using? – Adam Seabridge May 14 '19 at 17:02
  • @AdamSeabridge : Sitecore version 9.0.2 and WFFM version 9.0. – Shaurya May 15 '19 at 7:24
  • Are you using MVC or ASP.Net WebForms? – jammykam May 21 '19 at 16:16
  • ASP.Net WebForms. Not using MVC WFFM rendering as of now. – Shaurya May 22 '19 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.