Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing “for” attribute for label elements #560

Open
nclm opened this issue Mar 28, 2022 · 3 comments
Open

Missing “for” attribute for label elements #560

nclm opened this issue Mar 28, 2022 · 3 comments

Comments

@nclm
Copy link

nclm commented Mar 28, 2022

It seems that Grab generates form labels without for attributes:

<div class="form-field  ">
    <div class="form-label">
        <label class="inline">Name <span class="required">*</span></label>
    </div>
    <div class="form-data" data-grav-field="text" data-grav-disabled="" data-grav-default="null">
        <div class="form-input-wrapper ">
            <input name="data[name]" value="" type="text" class=" " placeholder="Your name" autofocus="autofocus" required="required">
        </div>
    </div>
</div>

However, for attributes are very important to create the connection between the label and the form field. This should be rather look like this:

<div class="form-field  ">
    <div class="form-label">
        <label for='name' class="inline">Name <span class="required">*</span></label>
    </div>
    <div class="form-data" data-grav-field="text" data-grav-disabled="" data-grav-default="null">
        <div class="form-input-wrapper ">
            <input id='name' name="data[name]" value="" type="text" class=" " placeholder="Your name" autofocus="autofocus" required="required">
        </div>
    </div>
</div>

Could this be implemented? Thanks!

@pamtbaau
Copy link

pamtbaau commented Mar 28, 2022

You might want to take a look at the documentation about forms. Especially about the id attribute in section Common Fields Attributes.

id sets the field id as well as the for attribute on the label

@hughbris
Copy link
Contributor

Because the value of labels is greatly reduced without id and setting id is not a requirement, my opinion is that I'd like to see a default id attribute set when it's not provided.

@nclm
Copy link
Author

nclm commented Mar 30, 2022

You might want to take a look at the documentation about forms. Especially about the id attribute in section Common Fields Attributes.

Oh thanks, I missed that!

Because the value of labels is greatly reduced without id and setting id is not a requirement, my opinion is that I'd like to see a default id attribute set when it's not provided

Yes, I agree as well. It could be randomly generated, generic like formname-field1, or even based on the name field (in which case the id attribute would be used to override the default). As long as it works. I cannot see a use case where someone would not want a for attribute on their labels, so it might as well be there by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants