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

Addons in combination with validations #4106

Open
InzeNL opened this issue Sep 14, 2022 · 8 comments
Open

Addons in combination with validations #4106

InzeNL opened this issue Sep 14, 2022 · 8 comments
Assignees
Labels
Type: Bug 🐞 Something isn't working

Comments

@InzeNL
Copy link
Contributor

InzeNL commented Sep 14, 2022

Describe the bug
When adding validation to a field in an Addon, the combination of an AddonType.Body and an AddonType.End breaks when a validation message shows up. When the validation message is not there, it looks fine.

To Reproduce
https://github.com/InzeNL/Blazorise-Addon-Feedback

  1. Create an <Addons> field with an AddonType.Body and an AddonType.End
  2. In the AddonType.Body add an *Edit field (in my code example it's a TextEdit, but NumericEdit gives the same issue
  3. Add validation to the *Edit field
  4. When a validation message shows up in the Feedback field, the AddonType.End will hop to the line under that message. When there is no validation message, the AddonType.End shows correctly

Expected behavior
The validation message should always show up under the addons field, if that is where the *Edit element is placed

Screenshots
image
image

Additional context
Perhaps adding the possibility to add a Feedback element to the addons element would be a solutiono.

@InzeNL InzeNL added the Type: Bug 🐞 Something isn't working label Sep 14, 2022
@stsrki
Copy link
Collaborator

stsrki commented Sep 14, 2022

You can add ValidationError anywhere inside of Validation. Feedback is mainly used to place it at the right place for the input. But addons are kinda different, so we need to adjust.

Try

<Validation Validator="@ValidateEventStartingDate">
    <Addons>
        <Addon AddonType="AddonType.Body">
            <DatePicker @ref="@startingDatePicker" TValue="DateTime?" InputMode="DateInputMode.Date" Date="@NewStreamEvent.StartingDate" DateChanged="@OnStartingDateChanged" DisplayFormat="dd-MM-Y" Disabled="@DisabledMode">
            </DatePicker>
        </Addon>
        <Addon AddonType="AddonType.End">
            <Button Color="Color.Light" Clicked="@(()=>startingDatePicker.ToggleAsync())">
                <Icon Name="IconName.CalendarDay" />
            </Button>
        </Addon>
        <ValidationError>@L["PleseSelectValidFutureStartingDateForEventDate"]</ValidationError>
    </Addons>
</Validation>

@InzeNL
Copy link
Contributor Author

InzeNL commented Sep 15, 2022

I changed my code to this:

<Validation Validator="ValidationRule.IsNotEmpty">
    <Addons>
        <Addon AddonType="AddonType.Body">
            <TextEdit Placeholder="Enter name">
                <Feedback>
                </Feedback>
            </TextEdit>
        </Addon>
        <Addon AddonType="AddonType.End">
            <AddonLabel>This is a label</AddonLabel>
        </Addon>
        <ValidationNone></ValidationNone>
        <ValidationSuccess></ValidationSuccess>
        <ValidationError>Enter valid name!</ValidationError>
    </Addons>
</Validation>

While the error message shows up correctly, with the AddonType.End in the right place, the AddonType.End does not have the expected rounded corners.
image

Trying to move the ValidationError outside of the Addons element does fix the rounded corners, but the message does not show up anymore

<Validation Validator="ValidationRule.IsNotEmpty">
    <Addons>
        <Addon AddonType="AddonType.Body">
            <TextEdit Placeholder="Enter name">
                <Feedback>
                </Feedback>
            </TextEdit>
        </Addon>
        <Addon AddonType="AddonType.End">
            <AddonLabel>This is a label</AddonLabel>
        </Addon>
    </Addons>
    <ValidationNone></ValidationNone>
    <ValidationSuccess></ValidationSuccess>
    <ValidationError>Enter valid name!</ValidationError>
</Validation>

image

@stsrki
Copy link
Collaborator

stsrki commented Sep 15, 2022

I don't that is wrong. The error is on an input element, not the label. So it is showing the border at the right place.

@InzeNL
Copy link
Contributor Author

InzeNL commented Sep 15, 2022

I would want the "This is a label" in the top picture to have rounded corners like the label in the bottom picture.
It doesn't do that because it's not the last element in the Addons section, which is how it should be expected.
Is there a way I can get the rounded corners on the label and show a ValidationError?

@stsrki
Copy link
Collaborator

stsrki commented Sep 15, 2022

You can see the same behavior on the Bootstrap documentation. https://getbootstrap.com/docs/5.0/forms/validation/

image

@InzeNL
Copy link
Contributor Author

InzeNL commented Sep 15, 2022

The difference between that and mine is that my label is an AddonType.End instead of an AddonType.Start

@Jimmys20
Copy link
Contributor

Jimmys20 commented Sep 15, 2022

@InzeNL is talking about theses corners:

190365827-ad210c1d-8b91-4600-abc4-6d6a8515fc13

which should be rounded:

190366131-f8f229fa-d3a6-4a08-a327-603d5acc94db

@stsrki the class has-validation needs to be added to the input-group element when it contains validation feedback in order to be displayed correctly:

<div class="input-group has-validation">

From bootstrap documentation:

To fix issues with border radii, input groups require an additional .has-validation class.

Adding has-validation class to the Addons component is the solution:

<Validation Validator="ValidationRule.IsNotEmpty">
    <Addons Class="has-validation">
        <Addon AddonType="AddonType.Body">
            <TextEdit Placeholder="Enter name"></TextEdit>
        </Addon>
        <Addon AddonType="AddonType.End">
            <AddonLabel>This is a label</AddonLabel>
        </Addon>
    </Addons>
    <ValidationNone></ValidationNone>
    <ValidationSuccess></ValidationSuccess>
    <ValidationError>Enter valid name!</ValidationError>
</Validation>

@stormitornado
Copy link

unfortunately, .has-validation creates another bug
image
Solutions which I see here is:
to move .invalid-feedback outside of .input-group and show/hide it with JS,
or to use modern CSS features, like :has() with grid layout.

@stsrki stsrki self-assigned this Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug 🐞 Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants