This is a migrated thread and some comments may be shown as answers.

CheckBoxFor + FluenValidation + Client side

3 Answers 123 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Pawel
Top achievements
Rank 1
Pawel asked on 06 Aug 2015, 06:00 AM
Hi,
I want to have client side for a checkbox. When the user presses submit button, or checkbox loose focus the validation should be trigged. Basically same behaviour as for textboxes (which are working fine).

I try to make client side validation for a CheckBox
Here is the sample code:
@Html.CheckBoxFor(model => model.RulesAccepted, new { @class = "control-label" })
@Html.ValidationMessageFor(model => model.RulesAccepted)


If I do similar to the example code (http://demos.telerik.com/aspnet-mvc/validator/index) checkbox is validated. If it is not check then I get an error, which is correct.
But there is number of issues preventing me to use that code:
1.Model passed back to the post action does not have boolean value set (RulesAccepted is the property name on the model)
2.I'm not able to plug-in fluent validation messages to display them to the user.

If I try to do any other way no message is appearing when it should.
In the code I have now the TextBoxes validators work fine. I have only problem with CheckBox validator.

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 10 Aug 2015, 06:54 AM

Hello Pawel,

 

As far as I understand you have a RulesAccepted field/property in your model definition. Based on the 1. issue the RulesAccepted property is not boolean, is this correct?

 

If yes - could you please clarify the following:

  1. What is the type of the RulesAccepted and what is the purpose of the check box element?     2. How the validation should work in this case? 

  3. What should the state of the check box element indicate? 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Pawel
Top achievements
Rank 1
answered on 10 Aug 2015, 07:32 AM

RulesAccepted is boolean. In model and in viewmodel.

 

This is simple checkbox used to clarify that user, who want to register on my portal has accepted the rules.

I want to fire the client-side validation using Kendo Validator, but if I do it like here http://demos.telerik.com/aspnet-mvc/validator/index then MVC does not bind the property in Action in Controller.

0
Accepted
Boyan Dimitrov
Telerik team
answered on 12 Aug 2015, 08:51 AM

Hello Pawel,

Please find attached a sample project that implements the desired functionality:  

     - CheckBoxFor helper is used in order to display a check box bound to the boolean property of the model.

     - Client validation is used to validate whether the check box is checked or not.

      -If the validation is passed successfully you can retrieve the entire model in the action method. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Validation
Asked by
Pawel
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Pawel
Top achievements
Rank 1
Share this question
or