dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.6k stars 25.29k forks source link

Accessing form elements from @code in Blazor #20720

Closed PSCRIMS closed 3 years ago

PSCRIMS commented 3 years ago

I could not find in EditForm validation for phone number so I am trying to get the value entered in a ediform trapping the onsubmit and checking the value. At this point I haven't made the onsubmit procedure async, I was intending to call an async procedure after validating the contents (that it had 10 digits after being cleaned. Not much to check the number exists but at least a start) The code in the function does not recognize the form variable.

<- does it have to be an async function?

... @code { private AllFieldsModel srcfields = new AllFieldsModel(); private string testPhone = ""; private void CheckData() { private string str= ""; str = @srcfields.CustPhone; <-- does not recognize neither srcfields nor CustPhone ... I have been trying to get an answer on stackoverflow with no avail... --- #### Document Details ⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.* * ID: 81a32115-33f8-7d06-aaf0-b8ce918b5527 * Version Independent ID: 31ad18df-1904-bbdd-cfed-8d0d0267c10e * Content: [Create and use ASP.NET Core Razor components](https://docs.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-5.0) * Content Source: [aspnetcore/blazor/components/index.md](https://github.com/dotnet/AspNetCore.Docs/blob/master/aspnetcore/blazor/components/index.md) * Product: **aspnet-core** * Technology: **aspnetcore-blazor** * GitHub Login: @guardrex * Microsoft Alias: **riande**
PSCRIMS commented 3 years ago

left out the next line where I bind the value <InputText id="phone" @bind-Value="srcfields.CustPhone" />

PSCRIMS commented 3 years ago

<InputText id="phone" @bind-Value="srcfields.CustPhone" />

PSCRIMS commented 3 years ago

Sorry, not "fluent" on opening an issue

guardrex commented 3 years ago

Hello @PSCRIMS ... I wish I could help, but I'm ⛰️⛏️🏃😅 swamped with work for the next few weeks and then taking an extended three-week vacation 🏖️. I won't be able to look at general support requests, unless perhaps they are for WASM security, until early 2021. I recommend that you continue to ask for community support. Again, I'm sorry that I can't address your issue, but this does look like a general programming problem and not something actionable for docs. Continue with SO and for immediate chat assistance, try Slack or Gitter for Blazor ...

If you find a doc missing a clear gotcha, then it does become actionable. Either leave a comment here with what the topic is missing (I'll re-open this issue) or open a new issue with the This page feedback form on the topic.