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

fix: FluentValidationMessage won't show message for an empty FluentTextArea component. #2144

Closed
MertYacan opened this issue Jun 4, 2024 · 5 comments
Labels
area:blazor A blazor-specific issue area:browsers A browser specific issue

Comments

@MertYacan
Copy link

MertYacan commented Jun 4, 2024

🐛 Bug Report

FluentValidationMessage doesn't show an error message for a fluent text area with required field set true.

💻 Repro or Code Sample

@page "/test"

<EditForm Model="@dto" OnValidSubmit="HandleValidSubmit" FormName="batchForm">
    <DataAnnotationsValidator />
    <FluentValidationSummary />

    <FluentStack Orientation="Orientation.Vertical">
        <div>
            <FluentTextArea Rows=5 Cols=60 Name="description" @bind-Value="dto.Description" Label="Description" Required="true" />
            <FluentValidationMessage For="@(() => dto.Description)" />  @* This won't show message *@
        </div>
        <div>
            From:
            <FluentDatePicker @bind-Value="@(dto.From)" Required />
            <FluentTimePicker @bind-Value="@(dto.From)" />
            <br />
        </div>
        <div>
            To:
            <FluentDatePicker @bind-Value="@(dto.To)" Required />
            <FluentTimePicker @bind-Value="@(dto.To)" />
            <br />
        </div>

        <FluentCheckbox @bind-Value="@(dto.IsAdministrative)" Disabled="true" Label="Administrative Leave" />
        <FluentButton Type="ButtonType.Submit" Appearance="Appearance.Accent" Disabled="@(processing)">Submit</FluentButton>
    </FluentStack>
</EditForm>

@code {
    [SupplyParameterFromForm]
    private CreateBatchLeaveExcelDto dto { get; set; } = new()
        {
            From = new DateTime(DateOnly.FromDateTime(DateTime.Now), new TimeOnly(8, 0)),
            To = new DateTime(DateOnly.FromDateTime(DateTime.Now), new TimeOnly(17, 0))
        };

    private bool processing = false;

    public class CreateBatchLeaveExcelDto
    {
        public DateTime? From { get; set; }
        public DateTime? To { get; set; }
        public string? Description { get; set; }
        public bool IsAdministrative { get; set; }
    }

    private async Task HandleValidSubmit()

    {
        processing = true;
        await Task.Delay(500);
        processing = false;
    }
}

🤔 Expected Behavior

Works with FluentTextField
image

😯 Current Behavior

Doesn't work with FluentTextArea
image

🌍 Your Environment

  • OS & Device: Windows on PC
  • Browser: Google Chrome
  • .NET and Fluent UI Blazor library Version 4.7.2
@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Jun 4, 2024
@vnbaaij vnbaaij added needs: repro code or repository The provided description or code is insufficient to repro the issue and removed triage New issue. Needs to be looked at labels Jun 4, 2024
@vnbaaij
Copy link
Collaborator

vnbaaij commented Jun 4, 2024

Hi,

Provided sample code is not ready-to-run. Please complement.

@MertYacan
Copy link
Author

Hi,

I am sorry. It should be ready-to-run now.

I realized when I run the app, and click submit it won't show the error message.

If i write something inside the description and clear the description again, then it will start to show the error message.

Thank you.

@vnbaaij
Copy link
Collaborator

vnbaaij commented Jun 4, 2024

It seems the standard HTML 5 validation checking and the FluentTextArea are not playing together nicely. I'll need to look into that further.

In the meantime I would advise you to not use the standard HTML validation but use Blazor's icw ours. Here is what you need to do:

  1. add @using System.ComponentModel.DataAnnotations at the top of your page
  2. add novalidate to your EditForm tag
  3. change your CreateBatchLeaveExcelDto class to have:
 [Required(ErrorMessage = "Description is required")]
 public string? Description { get; set; }

Then clicking submit will show you an error immediately(*)
image

Added benefit is that it will show the errors in the correct Fluent Design (as shown above) instead of the generic design (as shown below)
image
(which looks way worse if you ask ,e

(*) It will show the red border if below is in your CSS somewhere. I'm currently working on this and it will be automatically included in next release

fluent-text-area.invalid::part(control), 
fluent-text-field.invalid::part(root) {
    outline: calc(var(--stroke-width)* 1px) solid var(--error);
}

PS: Setting `Required="true" on a field does not automatically add any checks or logic. It's sole task (currently) is to display the required indicator (the red *)

@vnbaaij vnbaaij added area:blazor A blazor-specific issue area:browsers A browser specific issue and removed needs: repro code or repository The provided description or code is insufficient to repro the issue labels Jun 4, 2024
@vnbaaij
Copy link
Collaborator

vnbaaij commented Jun 4, 2024

Closing this as a workaround is provided

@vnbaaij vnbaaij closed this as completed Jun 4, 2024
@MertYacan
Copy link
Author

Hi Vincent,

Thank you very much for the detailed explanation. It worked with your suggested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:blazor A blazor-specific issue area:browsers A browser specific issue
Projects
None yet
Development

No branches or pull requests

2 participants