server side (controller) error message for password field not showing on client side

1 Answer 48 Views
Form
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 19 Aug 2021, 03:17 PM

I have two password fields on a form. I have used your demo way to change there editor to password boxes. If I validate in the controller and pass back an error message indicating they need to match the error message is not displayed. How do I correct this. I am open to preventing the submit with a little javascript validation so it never goes to the server. Please Advise.


                        i.Add()
                            .Field(f => f.Password)
                            .EditorTemplateHandler("setPasswordEditor")
                            .Label(l => l.Text("Password:"));

                        i.Add()
                            .Field(f => f.ConfirmPassword)
                            .EditorTemplateHandler("setConfirmPasswordEditor")
                            .Label(l => l.Text("Confirm Password:"));


        function setPasswordEditor(container, options) {
            container.append($("<input type='password' class='k-textbox k-valid' id='Password' name='Password' title='Password' required='required' autocomplete='off' aria-labelledby='Password-form-label' data-bind='value:Password' aria-describedby='Password-form-hint'>"));
        }
        function setConfirmPasswordEditor(container, options) {
            container.append($("<input type='password' class='k-textbox k-valid' id='ConfirmPassword' name='ConfirmPassword' title='Confirm Password' required='required' autocomplete='off' aria-labelledby='Password-form-label' data-bind='value:ConfirmPassword' aria-describedby='Password-form-hint'>"));
        }


            if (model.Password!=model.ConfirmPassword)
            {
                ModelState.AddModelError("Password", "Passwords Must Match");
                ModelState.AddModelError("ConfirmPassword", "Passwords Must Match");
                return View("UserEditView",model);
            }

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 24 Aug 2021, 02:58 PM

Hi David,

 

Thank you for writing to us.

The Validation demo of the Form demonstrates server-validation:
https://demos.telerik.com/aspnet-mvc/form/validation

However, you can also use Kendo Validator to prevent unmatching passwords to go to the controller at all:
https://demos.telerik.com/aspnet-mvc/validator

This Wizard + Form demo demonstrates a sample implementation:
https://demos.telerik.com/aspnet-mvc/wizard/form

I hope this will prove helpful for your scenario.

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
commented on 26 Aug 2021, 01:54 PM

Thanks Eyup for your answer.

I have actually seen the links you posted. I can definitely do this you the client side. 

My original question still stands though.  In my controller code (in my original posting) you will see that I am adding an error to the ModelState on the password and confirmpassword fields ... and yet they do not show when the page is rendered and they do not show in the validation summary. I am using the suggested way of making them passwords fields and i suspect that is what is culling the error displays.  None of your links provided address sending back a validation error from the server side for the password field. if I missed it please link it an i will take a look at that.

Eyup
Telerik team
commented on 31 Aug 2021, 02:01 PM

For the server-side validation part, can you open a formal support ticket to send us a very basic runnable MVC project demonstrating your exact configuration?

Then, we will modify it to find a viable solution and send the working version back to you.

Tags
Form
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Eyup
Telerik team
Share this question
or