No label tag for fields

Valentin_Antido
Level 1

No label tag for fields

Hi,

I wonder why there's no label tag for every field ?

It goes against W3C rules and specifically accessibility needs.

We'd like to wrap fields with a <label> tag which contain some properties like "for" and "aria-label".

Thanks a lot for any help.

3 REPLIES 3
Jay_Jiang
Level 10

Re: No label tag for fields

Some jQuery to add attribute to existing label

MktoForms2.whenReady(function (form) {

var $formEl = form.getFormElem(),

$inputs = $formEl.eq(0).find(':input');

$.each($inputs, function(){

$(this).parent().find('label').eq(0).attr("aria-label",$(this).attr("id"));

});

});

Or specifically wrapping the input with a new label:

MktoForms2.whenReady(function (form) {

var $formEl = form.getFormElem(),

$inputs = $formEl.eq(0).find(':input');

$.each($inputs, function(){

$(this).wrap('<label/>').parent().attr({"for":$(this).attr("id"),"aria-label":$(this).attr("id")});

});

});

SanfordWhiteman
Level 10 - Community Moderator

Re: No label tag for fields

Use MktoForms.$, not simply $, if you must depend on additional jQuery methods. Then you won't be requiring the person to include a separate framework.

Jay_Jiang
Level 10

Re: No label tag for fields

MktoForms2.whenReady(function (form) {

var $formEl = form.getFormElem(),

$inputs = $formEl.eq(0).find(':input');

MktoForms2.$.each($inputs, function(){

MktoForms2.$(this).wrap('<label/>').parent().attr({"for":MktoForms2.$(this).attr("id"),"aria-label":MktoForms2.$(this).attr("id")});

});

});