Skip to content

Validate passing unmatched attributes to Blazor form components #10790

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

Closed
12 tasks done
rynowak opened this issue Jun 3, 2019 · 5 comments
Closed
12 tasks done

Validate passing unmatched attributes to Blazor form components #10790

rynowak opened this issue Jun 3, 2019 · 5 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed Validation This issue is used to track validation efforts

Comments

@rynowak
Copy link
Member

rynowak commented Jun 3, 2019

Summary

Preview 6 adds the ability to pass arbitrary attributes to our form components and have them flow through to the underlying HTML element associated with the component.

Example: (the ability to specify placeholder is the usage of the new feature)

<EditForm Model="@exampleModel" OnValidSubmit="@HandleValidSubmit">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <InputText id="name" bind-Value="@exampleModel.Name" placeholder="Enter your name"/>

    <button type="submit">Submit</button>
</EditForm>

@functions {
    private ExampleModel exampleModel = new ExampleModel();

    private void HandleValidSubmit()
    {
        Console.WriteLine("OnValidSubmit");
    }
}

For now Class and Id are still defined as component parameters. This will be removed in preview 7 and these attributes will also use the unmatched attributes support.

For now the completion experience on the InputText element won't offer you attributes like placeholder in VS.

Checklist

  • Works with EditForm
  • Works with InputCheckbox
  • Works with InputDate
  • Works with InputNumber
  • Works with InputSelect
  • Works with InputText
  • Works with InputTextArea
  • Works with ValidationMessage
  • Works with ValidationSummary
  • Preserves original case of unmatched attributes
  • Forwards unmatched attributes regardless of order
  • Duplicate attributes differing only in casing results in a build error

References

@rynowak
Copy link
Member Author

rynowak commented Jun 3, 2019

note: this validation should be considered blocked until we have a d16.2 build with all of the editor fixes in it. Since it touches the editing experiences, we should do the validation of this feature once those things land.

@mkArtakMSFT mkArtakMSFT added the Validation This issue is used to track validation efforts label Jun 3, 2019
@ryanbrandenburg ryanbrandenburg added Working and removed blocked The work on this issue is blocked due to some dependency labels Jun 5, 2019
@ryanbrandenburg
Copy link
Contributor

I'm mostly done here, I found one issue and want to make one clarification:

  1. "Preserves original case of unmatched attributes" does not seem to hold true. If I put
<InputText Id="name" @bind-Value="@exampleModel.Name" firstOrLast="first" />

with will be output in html as:

<input id="name" firstorlast="first />
  1. "Forwards unmatched attributes regardless of order" I'm not 100% clear on what this means. I assume it means "even if the unmatched attributes are in something other than alphabetical order, they should still all be added."

1 doesn't seem like a blocker in either case, but definitly something @SteveSandersonMS should have a look at,.

If I get confirmation of my interpretation of 2 this will be good to go.

@ryanbrandenburg
Copy link
Contributor

2 didn't mean what I thought it did (actually meant that if we have an unbound parameter, a bound parameter, then further unbound parameters they should all end up in the right place) but it's been verified.

Leaving this option to get @SteveSandersonMS's opinion on "Preserves original case of unmatched attributes", but that's relatively minor, so we can count this as done for release purposes.

@rynowak
Copy link
Member Author

rynowak commented Jun 6, 2019

Preserves original case of unmatched attributes", but that's relatively minor, so we can count this as done for release purposes.

@SteveSandersonMS is there something that we're doing in the JS code to force attributes to lower case? I found this behaviour surprising and the compiled code has the original case.

@ryanbrandenburg
Copy link
Contributor

I think this is just something in the way that browsers handle attributes: If I just create a plain .html file with weirdly cased attributes they get lower-cased in Chrome and Firefox.

@ryanbrandenburg ryanbrandenburg added Done This issue has been fixed and removed Working labels Jun 6, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components Done This issue has been fixed Validation This issue is used to track validation efforts
Projects
None yet
Development

No branches or pull requests

4 participants