vtfuture / BForms

Bootstrap Forms for ASP.NET MVC
MIT License
62 stars 33 forks source link

Validation Issues #278

Open meister-d opened 8 years ago

meister-d commented 8 years ago

Hi BForms Team, I encountered some Validation Issues, that I wanted to share with you.

Password Fields After implementing the refreshing of the New Form as you stated in #271 i had some strange behaviour with Password Fields. When I type a password and the confirmation without refreshing the form, everything seems to work fine. But sometimes after refreshing the Form the confirmation Field turns Red although the passwords are the same.

I think you can see that it checks for different Values in the bforms.validate.js. After refreshing the targetval and value are not any more equal althought its the same Password:

// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
                equalTo: function (value, element, param) {
                    // bind to the blur event of the target in order to revalidate whenever the target field is updated
                    // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
                    var target = $(param);
                    if (this.settings.onfocusout) {
                        target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function () {
                            $(element).valid();
                        });
                    }

                    var targetval = target.val();

                    return value === targetval;
                },

Server Side Validation Another Issue I remarked was after experiencing errors Serverside. Use Case: Our Application is connected to a WebApi Service. After sending the New Form to the Server I get an Exception that eg the Contributions field musst have some value:

public BsJsonResult New(BsToolbarModel<ContributorSearchModel, ContributorNewModel> model)
        {
            var msg = string.Empty;
            var status = BsResponseStatus.Success;
            var row = string.Empty;

            try
            {
                if (ModelState.IsValid)
                {

                    if (String.IsNullOrEmpty(model.New.Contributions))
                    {
                        msg = "Please enter a Contribution";
                        throw new Exception("Something happened Serverside :-( Please Update the Contributions Field");
                    }
                    var rowModel = _gridRepository.Create(model.New);

                    var viewModel = _gridRepository.ToBsGridViewModel(rowModel).Wrap<ContributorsViewModel>(x => x.Grid);

                    row = this.BsRenderPartialView("Grid/_Grid", viewModel);
                }
                else
                {
                    return new BsJsonResult(
                        new Dictionary<string, object> { { "Errors", ModelState.GetErrors() } },
                        BsResponseStatus.ValidationError);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                status = BsResponseStatus.ServerError;
            }

            return new BsJsonResult(new
            {
                Row = row
            }, status, msg);
        }

When I now update the contributions Fields, the Error on top of the Row does not dissapear like it would be in Clientside model validation. I also have to press two times the submit button so that the Form gets resent. The First time the Error disappears and the second time the form is finnaly submitted.

To better illustrate my Issues I update my Sample Project. You can find it under the following Url: Sample on OneDrive Both issues are illustrated on the Contributors Models and Views

I really would appreciate if you could take some time to check my sample project.

Regards Dumitru

meister-d commented 8 years ago

Hi BForms Team, could anyone already have a look at this Issue? Is there any further information needed?

Regards Dumitru

meister-d commented 8 years ago

Hi Guys, any Inputs on this issues? Can somebody please have a Look at my Questions? Regards Dumitru

meister-d commented 8 years ago

Hi Guys, please tell me what information is needed so that you can have a look at this problem... Regards Dumitru

meister-d commented 8 years ago

Hi Guys, any Inputs on this issues? Can somebody please give me a hint...? Regards Dumitru