locked
How to validate userInput(s) without editForm in blazor wasm? RRS feed

  • Question

  • User-79977429 posted

    Hi

    I've create a simple create/edit patient form as follow :

    @if (Model != null)
    {    
        if (!IsNewMode)
        {
            <div class="form-group">
                <label for="patientID">Patient ID</label>
                <input id="patientID" type="text" class="form-control" @bind="Model.PatientID" disabled />
            </div>
        }
        <div class="form-group">
            <label for="txtFirstName">First Name</label>
            <input id="txtFirstName" type="text" class="form-control" @bind="Model.FirstName" />
            <ValidationMessage For="Model.FirstName"></ValidationMessage>
        </div>
        <div class="form-group">
            <label for="txtLastName">Last Name</label>
            <input id="txtLastName" type="text" class="form-control" @bind="Model.LastName" />
            <ValidationMessage For="Model.LastName"></ValidationMessage>
        </div>
    }
    else
    {
        <h6>No patient found for this id!</h6>
    }

    @code {
        [Parameter]
        public Patient Model { get; set; }

        [Parameter]
        public bool IsNewMode { get; set; } = false;

        protected override void OnInitialized()
        {
            base.OnInitialized();

            if (this.IsNewMode)
            {
                this.Model = new Patient();
            }
        }
    }

    But validationMessage tags not working! I think it related to editForm & i don't use editForm in my razor component.

    My question is that, Is there any way to validation userInput(s) without using editForm (like above code)?

    Thanks in advance

    Tuesday, March 30, 2021 9:25 PM

All replies