locked
RemoteAttribute? RRS feed

Answers

  • User-821857111 posted

    The RemoteAttribute depends on jQuery via the unobtrusive ajax library. There is nothing comparable in Blazor. You just need to wire up an event handler to the onchange event of an input that calls a service to perform validation as required. Something like this:

    <input value="@emailAddress" @onchange=@(e => validate(e)) />
    @code {
        string emailAddress { get; set; }
        async Task validate(ChangeEventArgs e)
        {
            if (await client.GetFromJsonAsync<bool>("/api/email/validate?emailAddress=" + e.Value))
            {
                emailAddress = e.Value.ToString();
            }
        }
    }

    The method at api/email/validate will contain the logic that ensures the value is valid, returning a bool either way. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 17, 2020 2:56 PM

All replies

  • User-821857111 posted

    The RemoteAttribute depends on jQuery via the unobtrusive ajax library. There is nothing comparable in Blazor. You just need to wire up an event handler to the onchange event of an input that calls a service to perform validation as required. Something like this:

    <input value="@emailAddress" @onchange=@(e => validate(e)) />
    @code {
        string emailAddress { get; set; }
        async Task validate(ChangeEventArgs e)
        {
            if (await client.GetFromJsonAsync<bool>("/api/email/validate?emailAddress=" + e.Value))
            {
                emailAddress = e.Value.ToString();
            }
        }
    }

    The method at api/email/validate will contain the logic that ensures the value is valid, returning a bool either way. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 17, 2020 2:56 PM
  • User2071951454 posted

    Thank you for the reply (and the bad news ), @Mikesdotnetting!  Obviously not a cool as adding an attribute and allowing things to "just work" but it will put me in the right direction.  I will probably encapsulate it in a component and use that instead.

    Monday, August 17, 2020 3:13 PM
  • User-474980206 posted

    Blazor uses data attribute validation, so you can create your own custom validators. But currently there is no async validation, so they should not be used for remote validation.

    Monday, August 17, 2020 7:49 PM