Inhalte aufrufen

Profilbild

FluentValidation Client Side Support in Plugins


3 Antworten zu diesem Thema

#1 Sherif Ahmed

Sherif Ahmed

    Benutzer

  • Members
  • 26 Beiträge

Geschrieben: 23 April 2017 - 17:36

I have a view model in my plugin which I decorated by [ValidatorAttribute] from FluentValidation,

and the my Validator inherits from SmartValidatorBase<> and are as simple as NotEmpty() no more.

 

but at run time the validation is only running on the server side while in client side no validation happens when the fields are empty.

 

Is there something missing from my side?

 

Regards,


Sherif Ahmed

Software Engineer

Egypt


#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3084 Beiträge

Geschrieben: 24 April 2017 - 09:03

Yes, fluent validation is a server-side validation (populates the model state). For client-side validation you can use jquery.validate.


Schöne Grüße aus Düsseldorf,
Marcus Gesing


#3 Sherif Ahmed

Sherif Ahmed

    Benutzer

  • Members
  • 26 Beiträge

Geschrieben: 24 April 2017 - 15:55

But Fluent validation supports some client side validation by default as per their documentation

https://github.com/J...C-5-integration

 

 

Note that FluentValidation will also work with ASP.NET MVC's client-side validation, but not all rules are supported. For example, any rules defined using a condition (with When/Unless), custom validators, or calls to Must will not run on the client side. The following validators are supported on the client:

  • NotNull/NotEmpty
  • Matches (regex)
  • InclusiveBetween (range)
  • CreditCard
  • Email
  • EqualTo (cross-property equality comparison)
  • Length

 

so in my validator, I'm just using 

NotEmpty

which is supported as a client side validation as well as server side.

 

am wrong?


Sherif Ahmed

Software Engineer

Egypt


#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3084 Beiträge

Geschrieben: 24 April 2017 - 16:27

That would require extra coding. I would use fluent validation for server side validation and Required attribute for client side validation.

Schöne Grüße aus Düsseldorf,
Marcus Gesing




Auf dieses Thema antworten