helloflask / bootstrap-flask

Bootstrap 4 & 5 helper for your Flask projects.
https://bootstrap-flask.readthedocs.io
Other
1.09k stars 189 forks source link

Support to not displaying labels for form inputs #47

Open PanderMusubi opened 4 years ago

PanderMusubi commented 4 years ago

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:

greyli commented 4 years ago

You can control this simply with the CSS below:

<style>
    .form-control-label { display: none; }
</style>
PanderMusubi commented 4 years ago

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 commented 3 years ago

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

PanderMusubi commented 2 years ago

For Bootstrap 5 it is:

.form-label {
    display: none;
}

At the moment in app.py:

Proposal to extend with:

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

PanderMusubi commented 2 years ago

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 commented 2 years ago

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

PanderMusubi commented 2 years ago

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

marmstr93ng commented 2 months ago

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