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

[Bug] #206

Open
saitoreeper opened this issue Dec 9, 2023 · 0 comments
Open

[Bug] #206

saitoreeper opened this issue Dec 9, 2023 · 0 comments
Labels
Bug Something isn't working Triage Issue needs to be triaged

Comments

@saitoreeper
Copy link

Describe the bug
I have a form with sub components on the form that is loaded as a wizzard. The validation trigger on the first page/component and the red error appears under the field.

On the next tab it doesn't highlight the error as red, I am extremely confused at this point why it is happening.
I can see there is errors because of my foreach at the top of every tab

To Reproduce
Main Page CSHTML
`
@* *@

            <div class="control-section e-tab-section ">
                <EditForm EditContext="@editContext">
                    <FluentValidationValidator @ref="_fluentValidationValidator" />

                    <ValidationSummary />
                    <CascadingValue Value="@editContext" Name="EditContext">

                        <SfTab CssClass="fill" @bind-SelectedItem="SelectedPage" LoadOn="ContentLoad.Init">
                            <TabItems>
                                <TabItem Disabled="@AddressPage">
                                    <ChildContent>
                                        <TabHeader IconCss="=nav-link active " Text="1. Address"></TabHeader>
                                    </ChildContent>
                                    <ContentTemplate>

                                        @if (ValidationResult.Errors.Count > 0)
                                        {
                                            <div class="card padding-card">
                                                <div class="card-body">
                                                    <h5 class="card-title mb-4">Advert Type</h5>

                                                    <div class="row">
                                                        <div class="form-group col-md-6">
                                                        <div class="alert alert-secondary" role="alert">
                                                            @foreach (var error in ValidationResult.Errors)
                                                            {
                                                                @error.ErrorMessage @: </br>
                                                            }
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        }

                                        <div class="card padding-card">
                                            <div class="card-body">
                                                <h5 class="card-title mb-4">Advert Type</h5>

                                                <div class="row">
                                                    <div class="form-group col-md-6">
                                                        <label>Advert Type <span class="text-danger">*</span></label>
                                                        <SfDropDownList class="form-control custom-select" TValue="int" TItem="PropertyCheckboxSelections" Placeholder="Select Advert Type" DataSource="@AdvertTypes" @bind-value="@AdvertTypeId">
                                                            <DropDownListFieldSettings Value="Id" Text="Name"></DropDownListFieldSettings>
                                                        </SfDropDownList>
                                                        <ValidationMessage For="@(() => PropertyRequest.AdvertType)"></ValidationMessage>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <Address PropertyRequest="PropertyRequest"></Address>

                                        <button type="submit" @onclick="ContinueToPropertyDescriptionPage" class="btn btn-success">NEXT</button>

                                    </ContentTemplate>
                                </TabItem>
                                <TabItem Disabled="@DescriptionPage">
                                    <ChildContent>
                                        <TabHeader Text="2. Property Description"></TabHeader>
                                    </ChildContent>
                                    <ContentTemplate>

                                        @if (ValidationResult.Errors.Count > 0)
                                        {
                                            <div class="card padding-card">
                                                <div class="card-body">
                                                    <h5 class="card-title mb-4">Advert Type</h5>

                                                    <div class="row">
                                                        <div class="form-group col-md-6">
                                                            <div class="alert alert-secondary" role="alert">
                                                                @foreach (var error in ValidationResult.Errors)
                                                                {
                                                                    @error.ErrorMessage @: </br>
                                                                }
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        }
                    <CascadingValue Value="@editContext" Name="EditContext">

                                        <PropertyDescription IsPrivate="IsPrivate" PropertiesMainRequest="PropertyRequest" AdvertTypeId="AdvertTypeId"></PropertyDescription>
                                        </CascadingValue>

                                        <button type="submit" @onclick="PreviousToPropertyAddressPage" class="btn btn-success">PREVIOUS</button>

                                        <button type="submit" @onclick="ContinueToPropertyListingTypePage" class="btn btn-success">NEXT</button>

                                    </ContentTemplate>
                                </TabItem>

                                <TabItem Disabled="@ListingTypePage">
                                    <ChildContent>
                                        <TabHeader Text="3. Listing Type"></TabHeader>
                                    </ChildContent>
                                    <ContentTemplate>

                                        @if (ValidationResult.Errors.Count > 0)
                                        {
                                            <div class="card padding-card">
                                                <div class="card-body">
                                                    <h5 class="card-title mb-4">Advert Type</h5>

                                                    <div class="row">
                                                        <div class="form-group col-md-6">
                                                            <div class="alert alert-secondary" role="alert">
                                                                @foreach (var error in ValidationResult.Errors)
                                                                {
                                                                    @error.ErrorMessage @: </br>
                                                                }
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        }

                                        <ListingType IsPrivate="IsPrivate" PropertiesMainRequest="PropertyRequest" AdvertTypeId="AdvertTypeId"></ListingType>

                                        <button type="submit" @onclick="PreviousToPropertyDescriptionPage" class="btn btn-success">PREVIOUS</button>

                                        <button type="submit" @onclick="ContinueToPropertyFeaturePage" class="btn btn-success">NEXT</button>
                                    </ContentTemplate>
                                </TabItem>

                                <TabItem Disabled="@FeaturesPage">
                                    <ChildContent>
                                        <TabHeader Text="4. Features"></TabHeader>
                                    </ChildContent>
                                    <ContentTemplate>

                                        <PropertyFeatures PropertyRequest="PropertyRequest"></PropertyFeatures>

                                        <SecurityFeatures PropertiesMainRequest="PropertyRequest"></SecurityFeatures>
                                        <div class="row" style="float:right;">
                                            <div class="col-md-12" style="">
                                                <div class="col-md-12" style="">
                                                    <button type="submit" @onclick="PreviousToListingTypePage" class="btn btn-success">PREVIOUS</button>

                                                    <button type="submit" @onclick="(() => ContinueToPropertyGalleryPage())" class="btn btn-success">NEXT</button>
                                                </div>
                                            </div>
                                        </div>

                                    </ContentTemplate>
                                </TabItem>

                                <TabItem Disabled="@GalleryPage">
                                    <ChildContent>
                                        <TabHeader Text="5. Gallery"></TabHeader>
                                    </ChildContent>
                                    <ContentTemplate>

                                        <PropertyGallery PropertyId="@PropertyId" PropertiesMainRequest="PropertyRequest"></PropertyGallery>

                                        <div class="row" style="float:right;">
                                            <div class="col-md-12" style="">
                                                <div class="col-md-12" style="">
                                                    <button type="submit" @onclick="(() => PreviousToPropertyFeaturesPage())" class="btn btn-success">PREVIOUS</button>

                                                    <button type="submit" @onclick="(() => CreateEditProperty())" class="btn btn-success">ADD PROPERTY</button>
                                                </div>
                                            </div>
                                        </div>
                                    </ContentTemplate>
                                </TabItem>
                            </TabItems>
                        </SfTab>
                    </CascadingValue>
                </EditForm>

            </div>
        </div>
    </div>
</div>
`

Main Page .cs responsible for the navigation

`
This method that triggers the first navigate works and highlight the error in the subcomponent
private async void ContinueToPropertyDescriptionPage()
{
if (PropertyRequest.PropertyAddressRequest == null)
{
PropertyRequest.PropertyAddressRequest = new PropertyAddressRequest();
}
var validationResult = await AgencyAddressCreateValidator.ValidateAsync(PropertyRequest);

        if (validationResult.IsValid)
        {

            DescriptionPage = false;
            SelectedPage = 1;
        }
        else
        {
            // Update the EditContext to trigger validation messages
            editContext.NotifyValidationStateChanged();

            // Handle validation errors, you can access them using validationResult.Errors
            foreach (var error in validationResult.Errors)
            {
                Console.WriteLine($"Property: {error.PropertyName}, Error: {error.ErrorMessage}");
            }
        }
    }

This form trigger doesn't trigger sub component errors
private async void ContinueToPropertyListingTypePage()
{
if (AdvertTypeId == 1 && IsPrivate == false)
{
ValidationResult = await AgencyDescriptionValidator.ValidateAsync(PropertyRequest);
}
else if (AdvertTypeId == 1 && IsPrivate == true)
{
ValidationResult = await PrivateDescriptionValidator.ValidateAsync(PropertyRequest);
}
else if (AdvertTypeId == 2 && IsPrivate == false)
{
ValidationResult = await AgencyToRentDescriptionValidator.ValidateAsync(PropertyRequest);
}
else if (AdvertTypeId == 2 && IsPrivate == true)
{
ValidationResult = await PrivateToRentListingTypeValidator.ValidateAsync(PropertyRequest);
}

        if (ValidationResult.IsValid)
        {
            ListingTypePage = false;
            SelectedPage = 2;
        }
        else
        {
            // Update the EditContext to trigger validation messages
            editContext.NotifyValidationStateChanged();

            // Handle validation errors, you can access them using validationResult.Errors
            foreach (var error in ValidationResult.Errors)
            {
                Console.WriteLine($"Property: {error.PropertyName}, Error: {error.ErrorMessage}");
            }
        }
    }

`

SubComponents
Address
`@using Syncfusion.Blazor.Buttons

Address
    <BlazorWasmGrpcWithAuth0.Client.Pages.Maps.GoogleMaps CanSelectAddress="true" AddressCallBack="HandleChildEvent">

    </BlazorWasmGrpcWithAuth0.Client.Pages.Maps.GoogleMaps>

    <div class="row">
        <div class="form-group col-md-4">
            <label>Address <span class="text-danger">*</span></label>
            <input @bind-value="AddressFields.FormattedAddress" type="text" class="form-control" placeholder="Address">
        </div>
    </div>

    <div class="row">
        <div class="form-group col-md-4">
            <label>Street Number <span class="text-danger">*</span></label>
            <input @bind-value="AddressFields.StreetNumber" type="text" class="form-control" placeholder="Street Number">
                <ValidationMessage For="@(() => PropertyRequest.PropertyAddressRequest.StreetNumber)"></ValidationMessage>

        </div>
        <div class="form-group col-md-4">
            <label>Locality <span class="text-danger">*</span></label>
            <input @bind-value="AddressFields.Locality" type="text" class="form-control" placeholder="Locality">
        </div>
        <div class="form-group col-md-4">
            <label>Sublocality Level 1 <span class="text-danger">*</span></label>
            <input @bind-value="AddressFields.SublocalityLevel1" type="text" class="form-control" placeholder="Sublocality Level 1">
        </div>
    </div>

    <div class="row">
        <div class="form-group col-md-4">
            <label>Administrative Area Level 1 <span class="text-danger">*</span></label>
            <input @bind-value="AddressFields.AdministrativeAreaLevel1" type="text" class="form-control" placeholder="Administrative Area Level 1">
        </div>
        <div class="form-group col-md-4">
            <label>Administrative Area Level 2 <span class="text-danger">*</span></label>
            <input @bind-value="AddressFields.AdministrativeAreaLevel2" type="text" class="form-control" placeholder="Administrative Area Level 2">
        </div>
        <div class="form-group col-md-4">
            <label>Country <span class="text-danger">*</span></label>
            <input @bind-value="AddressFields.Country" type="text" class="form-control" placeholder="Country">
        </div>
    </div>

    <div class="row">
        <div class="form-group col-md-4">
            <label>Postal Code<span class="text-danger">*</span></label>
            <input @bind-value="AddressFields.PostalCode" type="text" class="form-control" placeholder="Postal Code">
        </div>

@*


Latitude
<input @bind-value="AddressFields.Latitude" type="text" class="form-control" placeholder="Latitude">
@
@

Longitude

<input @bind-value="AddressFields.Longitude" type="text" class="form-control" placeholder="Longitude">
*@

        <div class="row">
            <div class="form-group col-md-4">
                <SfCheckBox @bind-Checked="@AddressFields.HideAddress"><b>Hide Address</b></SfCheckBox>
            </div>
        </div>
</div>
`

PropertyDescription (error doesn not trigger)
`@using Blazored.FluentValidation
@using Syncfusion.Blazor.Navigations
@using Syncfusion.Blazor.DropDowns
@* @using Syncfusion.Blazor.Calendars
@using Syncfusion.Blazor.Grids *@
@using Syncfusion.Blazor.Inputs
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons
@using GrpcProto.PropertyMain;

<div class="card padding-card">
    <div class="card-body">
        <h5 class="card-title mb-4">Property Title</h5>
        <div class="form-group">
            <label>Property Title <span class="text-danger">*</span></label>
            <input type="text" @bind-value="PropertiesMainRequest.PropertyTitle" class="form-control" placeholder="Enter Full Name">
            <ValidationMessage For="@(() => PropertiesMainRequest.PropertyTitle)"></ValidationMessage>
        </div>
        <div class="form-group">
            <label>Property Description <span class="text-danger">*</span></label>
            <textarea @bind="PropertiesMainRequest.Description" class="form-control" rows="4" placeholder="Detailed Description"></textarea>
            <ValidationMessage For="@(() => PropertiesMainRequest.Description)"></ValidationMessage>
        </div>
        <div class="row">
            <div class="form-group col-md-6">
                <label>Erf Size <span class="text-danger">*</span></label>
                <input type="number" class="form-control" placeholder="m²" @bind-value="PropertiesMainRequest.PropertyDetailsRequest.PropertySize" step="1">
                <ValidationMessage For="@(() => PropertiesMainRequest.PropertyDetailsRequest.PropertySize)"></ValidationMessage>
            </div>
            <div class="form-group col-md-6">
                <label>Floor Size <span class="text-danger">*</span></label>
                <input type="number" @bind-value="PropertiesMainRequest.PropertyDetailsRequest.FloorSize" class="form-control" placeholder="m²" step="1">
                <ValidationMessage For="@(() => PropertiesMainRequest.PropertyDetailsRequest.FloorSize)"></ValidationMessage>
            </div>

        </div>

        <div class="row">
            <div class="form-group col-md-6">
                <label>Bedrooms <span class="text-danger">*</span></label>
                <input type="number" class="form-control" @bind-value="PropertiesMainRequest.PropertyDetailsRequest.BedroomsCount" placeholder="Enter Bedrooms" step="1">
                <ValidationMessage For="@(() => PropertiesMainRequest.PropertyDetailsRequest.BedroomsCount)"></ValidationMessage>
            </div>

            <div class="form-group col-md-6">
                <label>Bathrooms <span class="text-danger">*</span></label>
                <input type="number" class="form-control" placeholder="Enter Bathrooms" @bind-value="PropertiesMainRequest.PropertyDetailsRequest.BathroomsCount" step="0.5">
                <ValidationMessage For="@(() => PropertiesMainRequest.PropertyDetailsRequest.BathroomsCount)"></ValidationMessage>
            </div>
        </div>
        <div class="row">
            <div class="form-group col-md-6">
                <label>Garages <span class="text-danger">*</span></label>
                <input type="number" class="form-control" placeholder="Enter Garages" @bind-value="PropertiesMainRequest.PropertyDetailsRequest.GaragesCount" step="1">
                <ValidationMessage For="@(() => PropertiesMainRequest.PropertyDetailsRequest.GaragesCount)"></ValidationMessage>
            </div>

            <div class="form-group col-md-6">
                <label>Parking <span class="text-danger">*</span></label>
                <input type="number" class="form-control" placeholder="Enter Parking" @bind-value="PropertiesMainRequest.PropertyDetailsRequest.ParkingCount" step="1">
                <ValidationMessage For="@(() => PropertiesMainRequest.PropertyDetailsRequest.ParkingCount)"></ValidationMessage>
            </div>
        </div>
        <div class="row">

            <div class="form-group col-md-6">
                <label>Internet</label>
                <SfDropDownList class="form-control custom-select" TValue="int" TItem="PropertyCheckboxSelections" Placeholder="Select Internet Type" DataSource="@InternetTypes" @bind-value="@PropertiesMainRequest.PropertyDetailsRequest.InternetTypeID">
                    <DropDownListFieldSettings Value="Id" Text="Name"></DropDownListFieldSettings>
                </SfDropDownList>

                @*  <select class="form-control custom-select">
                <option disabled>Select Internet</option>
                <option value="ADSL">ADSL</option>
                <option value="Dialup">Dialup</option>
                <option selected="selected" value="Fibre">Fibre</option>


                <option value="Satellite">Satellite</option>
                <option value="VDSL">VDSL</option>
                </select> *@
                <ValidationMessage For="@(() => PropertiesMainRequest.PropertyDetailsRequest.InternetTypeID)"></ValidationMessage>
            </div>

            <div class="form-group col-md-6">
                <label>Video URL</label>
                <input type="text" class="form-control" placeholder="Youtube, Vimeo, Dailymotion, etc..." @bind-value="PropertiesMainRequest.VideoUrl">
            </div>
        </div>

        <div class="row">
            <div class="form-group col-md-6">
                <label>Tiktok URL</label>
                <input type="text" id="TiktokURL" class="form-control" placeholder="Tiktok URL" @bind-value="PropertiesMainRequest.TikTokUrl">
            </div>
            <div class="form-group col-md-6">
            </div>
        </div>

    </div>
</div>

`

Validation Contextes
AgencyAddressValidator
`using BlazorWasmGrpcWithAuth0.Client.ValidationModels;
using FluentValidation;
using GrpcProto.PropertyMain;
using System;

namespace BlazorWasmGrpcWithAuth0.Client.Pages.Property.Validators.ForSale.Agency
{
public class AgencyAddressValidator : AbstractValidator
{
public AgencyAddressValidator()
{
RuleFor(x => x.PropertyAddressRequest.StreetNumber).NotEmpty()
.NotNull().WithMessage("Address Needs to be filled in.");
}
}
}
**AgencyDescriptionValidator**using BlazorWasmGrpcWithAuth0.Client.ValidationModels;
using FluentValidation;
using GrpcProto.PropertyMain;
using System;

namespace BlazorWasmGrpcWithAuth0.Client.Pages.Property.Validators.ForSale.Agency
{
public class AgencyDescriptionValidator : AbstractValidator
{
public AgencyDescriptionValidator()
{
RuleFor(x => x.PropertyTitle)
.NotEmpty().WithMessage("Property Title needs to be filled in.");

        RuleFor(x => x.Description)
            .NotEmpty().WithMessage("Property Description cannot be empty.");

        RuleFor(x => x.PropertyDetailsRequest.PropertySize)
            .NotEmpty().WithMessage("Property Size cannot be empty.");

        RuleFor(x => x.PropertyDetailsRequest.FloorSize)
            .NotEmpty().WithMessage("Floor Size cannot be empty.");

        RuleFor(x => x.PropertyDetailsRequest.BedroomsCount)
            .NotEmpty().WithMessage("Bedrooms Count cannot be 0 or less.");

        RuleFor(x => x.PropertyDetailsRequest.BathroomsCount)
            .GreaterThanOrEqualTo(0).WithMessage("Bathrooms Count cannot be 0 or less.");

        RuleFor(x => x.PropertyDetailsRequest.GaragesCount)
            .GreaterThanOrEqualTo(0).WithMessage("Garages Count cannot be 0 or less.");

        RuleFor(x => x.PropertyDetailsRequest.ParkingCount)
            .GreaterThanOrEqualTo(0).WithMessage("Parking Count cannot be 0 or less.");
    }
}

}
`

@saitoreeper saitoreeper added Bug Something isn't working Triage Issue needs to be triaged labels Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

1 participant