Enterprise-level component library based on Bootstrap and Blazor

star nuget master download license repo commit

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

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...

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

@layout ComponentLayout
@inject IStringLocalizer<Labels> LLocalizer
@page "/labels"

<h3>@LLocalizer["Title"]</h3>

<p>@((MarkupString)LLocalizer["P1"].Value)</p>

<ul class="ul-demo">
    <li>@((MarkupString)LLocalizer["UlLi1"].Value)</li>
    <li>@((MarkupString)LLocalizer["UlLi2"].Value)</li>
</ul>

<p>@((MarkupString)LLocalizer["P2"].Value)</p>

<Tips>
    <p>@((MarkupString)LLocalizer["Tips"].Value)</p>
</Tips>

<Block Title="@LLocalizer["Block1Title"]" Introduction="@LLocalizer["Block1Intro"]">
    <p><b>@LLocalizer["Block1P1"]</b></p>
    <ul class="ul-demo">
        <li>@((MarkupString)LLocalizer["Block1Li1"].Value)</li>
        <li>@((MarkupString)LLocalizer["Block1Li2"].Value)</li>
        <li>@((MarkupString)LLocalizer["Block1Li3"].Value)</li>
        <li>@((MarkupString)LLocalizer["Block1Li4"].Value)</li>
    </ul>

    <GroupBox Title="@LLocalizer["GroupBox1Title"]" style="margin-top: 1.5rem;">
        <div>@LLocalizer["GroupBox1D1"]</div>
        <div>@((MarkupString)LLocalizer["GroupBox1D2"].Value)</div>
        <div>@((MarkupString)LLocalizer["GroupBox1D3"].Value)</div>
        <div>@((MarkupString)LLocalizer["GroupBox1D4"].Value)</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="@Localizer[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>@LLocalizer["P3"]</b></p>
    <GroupBox Title="@LLocalizer["GroupBox2Title"]" class="mt-3">
        <div>@((MarkupString)LLocalizer["GroupBox2D1"].Value)</div>
        <div>@((MarkupString)LLocalizer["GroupBox2D2"].Value)</div>
        <div>@((MarkupString)LLocalizer["GroupBox2D3"].Value)</div>
        <div>@((MarkupString)LLocalizer["GroupBox2D4"].Value)</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="@Localizer[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>
</Block>

<Block Title="@LLocalizer["Block2Title"]" , Introduction="@(((MarkupString)LLocalizer["Block2Intro"].Value).ToString())">
    <p>@((MarkupString)LLocalizer["P4"].Value)</p>
    <GroupBox>
        <EditorForm Model="@Dummy">
            <FieldItems>
                <EditorItem @bind-Field="context.Hobby" Data="@Foo.GenerateHobbys(Localizer)">
                </EditorItem>
            </FieldItems>
        </EditorForm>
    </GroupBox>

    <p class="mt-3">@((MarkupString)LLocalizer["P5"].Value)</p>
    <GroupBox>
        <EditorForm Model="@Dummy" ShowLabel="false">
            <FieldItems>
                <EditorItem @bind-Field="context.Hobby" Data="@Foo.GenerateHobbys(Localizer)">
                </EditorItem>
            </FieldItems>
        </EditorForm>
    </GroupBox>
</Block>

<Block Title="@LLocalizer["Block3Title"]" , Introduction="@(((MarkupString)LLocalizer["Block3Intro"].Value).ToString())">
    <p>@((MarkupString)LLocalizer["P6"].Value)</p>
    <GroupBox>
        <ValidateForm Model="@Dummy">
            <EditorForm TModel="Foo">
                <FieldItems>
                    <EditorItem @bind-Field="context.Hobby" Data="@Foo.GenerateHobbys(Localizer)">
                    </EditorItem>
                </FieldItems>
            </EditorForm>
        </ValidateForm>
    </GroupBox>

    <p class="mt-3">@((MarkupString)LLocalizer["P7"].Value)</p>
    <GroupBox>
        <ValidateForm Model="@Dummy" ShowLabel="false">
            <EditorForm TModel="Foo">
                <FieldItems>
                    <EditorItem @bind-Field="context.Hobby" Data="@Foo.GenerateHobbys(Localizer)">
                    </EditorItem>
                </FieldItems>
            </EditorForm>
        </ValidateForm>
    </GroupBox>
</Block>

<Block Title="@LLocalizer["Block4Title"].Value" , Introduction="@LLocalizer["Block4Intro"]">
    <p>@((MarkupString)LLocalizer["P8"].Value)</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">@((MarkupString)LLocalizer["P9"].Value)</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">@((MarkupString)LLocalizer["P10"].Value)</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>
</Block>
// 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 BootstrapBlazor.Shared.Pages.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using System.Diagnostics.CodeAnalysis;

namespace BootstrapBlazor.Shared.Pages
{
    /// <summary>
    /// 
    /// </summary>
    public partial class Labels : ComponentBase
    {
        [Inject]
        [NotNull]
        private IStringLocalizer<Foo>? Localizer { get; set; }

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

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

            Dummy = Foo.Generate(Localizer);
        }
    }
}

B 站相关视频链接

暂无

交流群

QQ Group:BootstrapAdmin & Blazor 795206915( Full) 675147445 Welcome to join the group discussion
Themes
Bootstrap
Ant Design (完善中)
Bluma (完善中)
LayUI (完善中)
Motronic (已集成)
An error has occurred. This application may no longer respond until reloaded. Reload