Enterprise-level component library based on Bootstrap and Blazor
gitee
version
license
download
repo
commit
build
coverage

Component label

This set of components includes ValidateForm EditorForm and a variety of Form components inherited from ValidateBase<TValue>. Among these components There is a special set of display front label logic, now let’s sort it out in a unified way:

  • The ValidateForm component is a verifiable form component. The form component in this component will automatically perform data compliance checks. If Data non-compliance will prevent the Submit action, which is the most frequently used component in data submission
  • The EditorForm component is an ordinary form component. After this component is bound to the Model, the entire form can be automatically generated, which greatly reduces repetition Code, put the ValidateForm on the outside to open the data compliance check very convenient, concise and efficient

Take the BootstrapInput input box component as an example to explain whether to display the Label logic

Suitable for data entry

Demo

When two-way binding is not used

  • Label will not be displayed by default
  • Control whether to display through the ShowLabel property
  • Display content when setting DisplayText
  • When not set, render a contentless label component as a placeholder
No settings in the first text box, no label
The second text box setting ShowLabel='true' DisplayText=`` displays a placeholder label without content
The third text box setting ShowLabel='true' DisplayText='Name' shows the set content label
The fourth text box setting ShowLabel='true' DisplayText='@@null' displays a placeholder label without content

When using two-way binding

The first text box is set to @@bind-Value='Dummy.Name', no label is displayed
The second text box setting @@bind-Value='Dummy.Name' ShowLabel='true' DisplayText='@@Localizer[nameof(Foo.Address)]' Display the contents of the setting
The third text box setting @@bind-Value='Dummy.Name' ShowLabel='true' DisplayText=`` Show no content placeholder label
The fourth text box setting @@bind-Value='Dummy.Name' ShowLabel='true' DisplayText='@@null' Display the label content under the resource file mechanismLabel code>

Not used in ValidateForm

Demo

Do not display labels

Set ShowLabel="false", all form components in the component Do not display tags

Loading...

Show label

The ShowLabel property of the EditorForm component is not set. If it is not set, it is equivalent to set to true. All components display tags

Loading...

Alignment

LabelAlign="Alignment.Right" set the label alignment is right

Loading...

Alignment

LabelAlign="Alignment.Center" set the label alignment is center

Loading...

Used in external ValidateForm

Demo

Show label

The ShowLabel property of the EditorForm component is not set. If it is not set, it is equivalent to set to true. All components display tags

Loading...

Do not display labels

Set ShowLabel="false", all form components in the component Do not display tags

Loading...

Show labels are automatically turned on by default

Demo

Show label

The ShowLabel property of the EditorForm component is not set. If it is not set, it is equivalent to set to true. All components display tags

Do not display labels

Set ShowLabel="false", all form components in the component Do not display tags

Show labels

set class form-inline for the all labels within the component are prefixed

Right

form-inline-end set the label alignment is right

Center

form-inline-center set the label alignment is center

Tooltip

The default width of component front label is 120px. If you need more, please change the style variable --bb-row-label-width in the project style file or remove RowType.Inline
In this example, set the ShowLabelTooltip in the form-inline style to true to make the mouse hover over the cropped label to display the complete information

@layout ComponentLayout
@page "/labels"

<h3>Component label</h3>

<p>This set of components includes <code>ValidateForm</code> <code>EditorForm</code> and a variety of <b>Form components</b> inherited from <code>ValidateBase<TValue></code>. Among these components There is a special set of display front label logic, now let’s sort it out in a unified way:</p>

<ul class="ul-demo">
    <li>The <a href='/validateforms' target='_blank'>ValidateForm</a> component is a <b>verifiable</b> form component. The form component in this component will automatically perform data compliance checks. If Data non-compliance will prevent the <b>Submit</b> action, which is the most frequently used component in data submission</li>
    <li>The <a href='/editorforms' target='_blank'>EditorForm</a> component is an ordinary form component. After this component is bound to the <code>Model</code>, the entire form can be automatically generated, which greatly reduces repetition Code, put the <code>ValidateForm</code> on the outside to open the <b>data compliance check</b> very convenient, concise and efficient</li>
</ul>

<p>Take the <a href='inputs' target='_blank'>BootstrapInput</a> input box component as an example to explain whether to display the <code>Label</code> logic</p>

<Tips>
    <p>The logic of <code>ShowLabel</code> is the principle of proximity. The closer the setting is to itself, the setting takes effect. For example, the form component is built into the <code>ValidateForm</code> component, even if <code>ValidateForm</code> is set to <code>>ShowLabel=true</code>, when the form component itself sets <code>ShowLabel=false</code>, the final result of the label is <b>not displayed</b></p>
</Tips>

<DemoBlock Title="Use alone" Introduction="Suitable for data entry" Name="Normal">
    <p><b>When two-way binding is not used</b></p>
    <ul class="ul-demo mb-3">
        <li><code>Label</code> will not be displayed by default</li>
        <li>Control whether to display through the <code>ShowLabel</code> property</li>
        <li>Display content when setting <code>DisplayText</code></li>
        <li>When not set, render a contentless <code>label</code> component as a placeholder</li>
    </ul>

    <GroupBox Title="No two-way binding" style="margin-top: 1.5rem;">
        <div>No settings in the first text box, no label</div>
        <div>The second text box setting <code>ShowLabel='true' DisplayText=``</code> displays a placeholder label without content</div>
        <div>The third text box setting <code>ShowLabel='true' DisplayText='Name'</code> shows the set content label</div>
        <div>The fourth text box setting <code>ShowLabel='true' DisplayText='@null'</code> displays a placeholder label without content</div>
        <div class="row g-3 mt-3">
            <div class="col-sm-12 col-md-3">
                <BootstrapInput TValue="string" />
            </div>
            <div class="col-sm-12 col-md-3">
                <BootstrapInput TValue="string" ShowLabel="true" DisplayText="" />
            </div>
            <div class="col-sm-12 col-md-3">
                <BootstrapInput TValue="string" ShowLabel="true" DisplayText="@LocalizerFoo[nameof(Foo.Name)]" />
            </div>
            <div class="col-sm-12 col-md-3">
                <BootstrapInput TValue="string" ShowLabel="true" DisplayText="@null" />
            </div>
        </div>
    </GroupBox>

    <p class="mt-3"><b>When using two-way binding</b></p>
    <GroupBox Title="Two-way binding" class="mt-3">
        <div>The first text box is set to <code>@bind-Value='Dummy.Name'</code>, no label is displayed</div>
        <div>The second text box setting <code>@bind-Value='Dummy.Name' ShowLabel='true' DisplayText='@Localizer[nameof(Foo.Address)]'</code> Display the contents of the setting</div>
        <div>The third text box setting <code>@bind-Value='Dummy.Name' ShowLabel='true' DisplayText=``</code> Show no content placeholder label</div>
        <div>The fourth text box setting <code>@bind-Value='Dummy.Name' ShowLabel='true' DisplayText='@null'</code> Display the label content under the resource file mechanism<code>Label</code> code></div>
        <div class="row g-3 mt-3">
            <div class="col-sm-12 col-md-3">
                <BootstrapInput @bind-Value="Dummy.Name" />
            </div>
            <div class="col-sm-12 col-md-3">
                <BootstrapInput @bind-Value="Dummy.Name" ShowLabel="true" DisplayText="@LocalizerFoo[nameof(Foo.Address)]" />
            </div>
            <div class="col-sm-12 col-md-3">
                <BootstrapInput @bind-Value="Dummy.Name" ShowLabel="true" DisplayText="" />
            </div>
            <div class="col-sm-12 col-md-3">
                <BootstrapInput @bind-Value="Dummy.Name" ShowLabel="true" DisplayText="@null" />
            </div>
        </div>
    </GroupBox>
</DemoBlock>

<DemoBlock Title="Used in EditorForm" Introduction="Not used in <code>ValidateForm</code>" Name="EditorForm">
    <p><b>Do not display labels</b><div>Set <code>ShowLabel="false"</code>, all form components in the component <b>Do not display</b> tags</div></p>
    <GroupBox>
        <EditorForm Model="@Dummy" ShowLabel="false" RowType="RowType.Inline" ItemsPerRow="2">
            <FieldItems>
                <EditorItem @bind-Field="context.Hobby" Items="@Foo.GenerateHobbys(LocalizerFoo)">
                </EditorItem>
            </FieldItems>
        </EditorForm>
    </GroupBox>

    <p class="mt-3"><b>Show label</b><div>The <code>ShowLabel</code> property of the <coe>EditorForm</coe> component is not set. If it is not set, it is equivalent to set to <code>true</code>. All components <b>display</b> tags</div></p>
    <GroupBox>
        <EditorForm Model="@Dummy" RowType="RowType.Inline" ItemsPerRow="2">
            <FieldItems>
                <EditorItem @bind-Field="context.Hobby" Items="@Foo.GenerateHobbys(LocalizerFoo)">
                </EditorItem>
            </FieldItems>
        </EditorForm>
    </GroupBox>

    <p class="mt-3"><b>Alignment</b><div><code>LabelAlign="Alignment.Right"</code> set the label alignment is right</div></p>
    <GroupBox>
        <EditorForm Model="@Dummy" ShowLabel="true" RowType="RowType.Inline" ItemsPerRow="2" LabelAlign="Alignment.Right">
            <FieldItems>
                <EditorItem @bind-Field="context.Hobby" Items="@Foo.GenerateHobbys(LocalizerFoo)">
                </EditorItem>
            </FieldItems>
        </EditorForm>
    </GroupBox>

    <p class="mt-3"><b>Alignment</b><div><code>LabelAlign="Alignment.Center"</code> set the label alignment is center</div></p>
    <GroupBox>
        <EditorForm Model="@Dummy" ShowLabel="true" RowType="RowType.Inline" ItemsPerRow="2" LabelAlign="Alignment.Center">
            <FieldItems>
                <EditorItem @bind-Field="context.Hobby" Items="@Foo.GenerateHobbys(LocalizerFoo)">
                </EditorItem>
            </FieldItems>
        </EditorForm>
    </GroupBox>
</DemoBlock>

<DemoBlock Title="Use in EditorForm built-in ValidateForm" Introduction="Used in external <code>ValidateForm</code>" Name="ValidateForm1">
    <p><b>Show label</b><div>The <code>ShowLabel</code> property of the <coe>EditorForm</coe> component is not set. If it is not set, it is equivalent to set to <code>true</code>. All components <b>display</b> tags</div></p>
    <GroupBox>
        <ValidateForm Model="@Dummy">
            <EditorForm TModel="Foo" RowType="RowType.Inline" ItemsPerRow="2">
                <FieldItems>
                    <EditorItem @bind-Field="context.Hobby" Items="@Foo.GenerateHobbys(LocalizerFoo)">
                    </EditorItem>
                </FieldItems>
            </EditorForm>
        </ValidateForm>
    </GroupBox>

    <p class="mt-3"><b>Do not display labels</b><div>Set <code>ShowLabel="false"</code>, all form components in the component <b>Do not display</b> tags</div></p>
    <GroupBox>
        <ValidateForm Model="@Dummy" ShowLabel="false">
            <EditorForm TModel="Foo" RowType="RowType.Inline" ItemsPerRow="2">
                <FieldItems>
                    <EditorItem @bind-Field="context.Hobby" Items="@Foo.GenerateHobbys(LocalizerFoo)">
                    </EditorItem>
                </FieldItems>
            </EditorForm>
        </ValidateForm>
    </GroupBox>
</DemoBlock>

<DemoBlock Title="Used in ValidateForm" Introduction="Show labels are automatically turned on by default" Name="ValidateForm2">
    <p><b>Show label</b><div>The <code>ShowLabel</code> property of the <coe>EditorForm</coe> component is not set. If it is not set, it is equivalent to set to <code>true</code>. All components <b>display</b> tags</div></p>
    <ValidateForm Model="@Dummy">
        <div class="row g-3">
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Name" />
            </div>
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Address" />
            </div>
        </div>
    </ValidateForm>

    <p class="mt-3"><b>Do not display labels</b><div>Set <code>ShowLabel="false"</code>, all form components in the component <b>Do not display</b> tags</div></p>
    <ValidateForm Model="@Dummy" ShowLabel="false">
        <div class="row g-3">
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Name" />
            </div>
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Address" />
            </div>
        </div>
    </ValidateForm>

    <p class="mt-3"><b>Show labels</b><div>set class <code>form-inline</code> for the all labels within the component are prefixed</div></p>
    <ValidateForm Model="@Dummy">
        <div class="row g-3 form-inline">
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Name" />
            </div>
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Address" />
            </div>
        </div>
    </ValidateForm>

    <p class="mt-3"><b>Right</b><div><code>form-inline-end</code> set the label alignment is right</div></p>
    <ValidateForm Model="@Dummy">
        <div class="row g-3 form-inline form-inline-end">
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Name" />
            </div>
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Address" />
            </div>
        </div>
    </ValidateForm>
    <p class="mt-3"><b>Center</b><div><code>form-inline-center</code> set the label alignment is center</div></p>
    <ValidateForm Model="@Dummy">
        <div class="row g-3 form-inline form-inline-center">
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Name" />
            </div>
            <div class="col-sm-12 col-md-6">
                <BootstrapInput @bind-Value="Dummy.Address" />
            </div>
        </div>
    </ValidateForm>

    <p class="mt-3">
        <b>Tooltip</b>
        <div>@((MarkupString)LocalizerForm["FormLabelWidth"].Value)</div>
        <div class="mt-2">@((MarkupString)LocalizerForm["LongDisplayDescription"].Value)</div>
    </p>
    <ValidateForm Model="@Dummy">
        <div class="row g-3">
            <div class="col-12">
                <BootstrapInput @bind-Value="@Dummy.Name" DisplayText="@LocalizerForm["LongDisplayText"]" />
            </div>
        </div>
        <div class="row g-3 form-inline mt-0">
            <div class="col-12">
                <BootstrapInput @bind-Value="@Dummy.Address" DisplayText="@LocalizerForm["LongDisplayText"]" ShowLabelTooltip="true" />
            </div>
        </div>
    </ValidateForm>
</DemoBlock>
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;

namespace BootstrapBlazor.Shared.Samples;

/// <summary>
/// 
/// </summary>
public partial class Labels : ComponentBase
{
    [Inject]
    [NotNull]
    private IStringLocalizer<Foo>? LocalizerFoo { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<Labels>? Localizer { get; set; }

    [Inject]
    [NotNull]
    private IStringLocalizer<ValidateForms>? LocalizerForm { get; set; }

    [NotNull]
    private Foo? Dummy { get; set; }

    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Dummy = Foo.Generate(LocalizerFoo);
    }
}

B 站相关视频链接

暂无

交流群

QQ Group:BootstrapAdmin & Blazor 795206915 675147445 Welcome to join the group discussion
Themes
Bootstrap
Motronic
Ant Design (完善中)
LayUI (完善中)
An error has occurred. This application may no longer respond until reloaded. Reload
Seems like the connection with the server has been lost. It can be due to poor or broken network. Please hang on while we're trying to reconnect...
Oh snap! Failed to reconnect with the server. This is typically caused by a longer network outage, or if the server has been taken down. You can try to reconnect, but if that does not work, you need to reload the page.
Oh man! The server rejected the attempt to reconnect. The only option now is to reload the page, but be prepared that it won't work, since this is typically caused by a failure on the server.
Bootstrap Blazor 组件库 更新到 6.6.0

首先感谢您对本套组件的关注,本目前本套组件已经拥有超过 120 个组件,本组件是基于 Bootstrap 风格的 Blazor 企业级组件库,提供如布局、导航、表单、数据、通知、图标、语音等几大类通用组件,每一个组件都经过静心设计,具有模块化、响应式和优秀的性能。从更多实际场景出发,满足多种场景的需求,极大的减少开发者时间成本,大大缩短开发周期,大幅提高开发效率,并提供了一套 通用权限管理系统 示例工程。Bootstrap Blazor 产品是由一支专业的全职技术团队进行维护,高效的响应速度,多元化的解决方案,长期提供支持,并提供企业级支持。目前已在多家知名国企内部使用,项目最高在线 1200 人稳定运行。右侧为国内人数最多的中文 Blazor QQ 社区二维码,欢迎扫描加群。

组件更新到 6.6.0 更新日志 [传送门] 如果组件给您带来了方便,请您帮忙给项目点亮 Star github gitee

QQGroup
QQ 795206915