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

Support to not displaying labels for form inputs #47

Open
PanderMusubi opened this issue Dec 7, 2019 · 8 comments
Open

Support to not displaying labels for form inputs #47

PanderMusubi opened this issue Dec 7, 2019 · 8 comments
Labels
enhancement New feature or request form

Comments

@PanderMusubi
Copy link
Collaborator

When a WTForms field has no label, a label is generated from the variable name it is assigned to, e.g. for a TextAreaWidget. This is very useful (convention over configuration).

However, in certain cases, the label of an input is not added to thre resulting HTML. What parameter can be used when creating a WTForm field in order to extend the form template here to not add the label around an input?

This relates to:

@ghost ghost mentioned this issue Jan 19, 2020
@greyli greyli added the feature label Apr 21, 2020
@greyli greyli changed the title Not displaying labels for form inputs Suuport to not displaying labels for form inputs Apr 21, 2020
@greyli
Copy link
Member

greyli commented Apr 25, 2020

You can control this simply with the CSS below:

<style>
    .form-control-label { display: none; }
</style>

@PanderMusubi
Copy link
Collaborator Author

I'd need to set this separately for each text area, so looking for a way to do this directly from Python when creating the particular field or from Python for all fields that do not have a label as to minimize using CSS.

@PanderMusubi PanderMusubi changed the title Suuport to not displaying labels for form inputs Support to not displaying labels for form inputs May 6, 2020
@PanderMusubi
Copy link
Collaborator Author

@greyli Any new thoughts on how to support this from Python?

@greyli greyli added enhancement New feature or request form and removed feature labels Jun 10, 2021
@PanderMusubi
Copy link
Collaborator Author

For Bootstrap 5 it is:

.form-label {
    display: none;
}

At the moment in app.py:

  • specify a label, the label is used
  • do not specify a label (i.e. None), the object name is used as label, which is a good way to default it

Proposal to extend with:

  • using empty string '' to hide the label (if one needs an empty label, use a space ' ', both should be documented)

This keeps the current behaviour and only extends it. Benefit is that all can be achieved without using custom CSS.

@PanderMusubi
Copy link
Collaborator Author

This would involve overriding https://github.com/wtforms/wtforms/blob/master/src/wtforms/fields/core.py#L446 so it returns an empty string. I'm not sure if we would like to do this or how we can do this. Any ideas? @greyli

@PanderMusubi
Copy link
Collaborator Author

If we cannot accommodate a solution, would it be a feature request for wtforms?

@PanderMusubi
Copy link
Collaborator Author

Would this also be a feature request for wtforms? https://github.com/greyli/bootstrap-flask/blob/master/flask_bootstrap/__init__.py#L9

@marmstr93ng
Copy link

marmstr93ng commented Apr 11, 2024

Setting form_type="inline" hides the label (e.g. <label class="visually-hidden" for="username">Username</label>) , could this be a solution too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request form
Projects
None yet
Development

No branches or pull requests

3 participants