Disable Grails Scaffolding Validation for one Class - validation

We use the Grails scaffolding for our internal part of our web app. Now we have the requirement to modify some values in the before validate method. The Problem is, that these fields are blank: false or nullable: true
It's no problem to modify these values in the beforeValidate method, but the problem is, that the scaffolding adds a required attribute to the html form, and so we can't submit it with these empty fields.
Is there a way to disable the scaffolding validation on a specific view for a specific class?
Greetings

The short answer is "No, there isn't a way to turn of validation for a specific domain class in scaffolding."
However, you can always generate the views for the domain class and edit the GSPs to remove the required attributes on the fields in question.
grails generate-views com.somewhere.MyDomainClass
Scaffolding is to get you a starting point to work from, not continued use and customization.

Related

Laravel place validation stuff

Laravel version - 5.0.0
Laravel offers so many ways to validate so I cannot choose what to use. Because no one of them suits my tastes.
What I want: full management of validation process. I want a class which:
has got rules property, but it I can modify them any time
can return break validation process if any rule fails; add rules to validator
has got custom messages
communicate with other classes which have got validate method as well as their own messages.
manage redirects and return values
Basically I do not want to extend validation class but simple use it. I think, form requests could do what I want. But now I do not understand their purpose. They are very poor in Laravel. Also, I do not want place all this in controller.
So, the only way is to create a custom class?

ASP.NET MVC 3: model-level client-side or remote validation

I need to do some model-level validation in an MVC 3 edit page. (To be specific, I need to confirm that either Field A or Field B is filled in, but not both and not neither.)
I want to perform client-side validation as well as server-side validation, which means either using remote validation or implementing duplicate validation code. I'm OK with either.
I've read a number of posts on rolling your own server-side model-level validation, but none that deal with also implementing client side validation. (I don't know -- I'm sure someone out there can tell me -- whether model-level client-side validation is easy to set up with jQuery validation.)
I've also read about implementing your own remote validation from scratch, which I may have to do since the Remote attribute is property-level only.
I've read this question, which is identical to mine, but the only link that's really on-point doesn't seem to say what the answerer says it says.
So, my question: is there an easy, relatively low-effort way to implement server+client model-level validation, with or without a remote component? And is there a nice blog post or web page somewhere that explains this?
I think Data Annotation Extention by Scott Kirkland does exactly what you want.
Here is a blog post he wrote about his extensions.
The core library provides server-side validation attributes that can be used in any .NET 4.0 project (no MVC dependency). There is also an easily pluggable client-side validation library which can be used in ASP.NET MVC 3 projects using unobtrusive jquery validation (only MVC3 included javascript files are required).
There is a similar question answered here which may be of some help? The answer given is for validating that at least one field is entered but the principles given in the answer may be what you are looking for and you should be able to change the answer to suit the validation you require. The solution also offers both server and client side validation options and I believe you can use the solution as both module or property level validation?
Additionally, there is also the following article here detailing how to create your own custom validation similar to that provided in the answer I linked to.
Hope this helps.
If i get you right, mvc 3 do actually include jquery client-side validation.
First, for the model-level server side validation, you can override the default isValid function with your own validation rules, something like this (involve multi-field):
public sealed class PropertyAAttribute : ValidationAttribute
{
public string propertyBAttribute { get; set; }
public override bool IsValid(object value)
{
// Your validation rule here
}
}
[PropertyA(propertyBAttribute = "PropertyB")]
public object PropertyA {get;set;}
public object PropertyB {get;set;}
Then, to deal with client side, you can simply use the included jquery validation function:
var frm = $('#formData');
frm.validate();
Like this, you will have the error message at client side based on the rule you defined in the model.
Hope this is what you need :)

Inserting a ModelValidator into a Model's Validators in ASP.NET MVC3

I'm currently trying to programmatically insert a ModelClientValidationStringLengthRule ModelValidator via a custom attribute, and wishing to avoid adding to the AdditionalValues dictionary in order to make use of existing functionality.
This is due to using a CMS, and wanting to control the length of the string via the CMS rather than within a model.
I assume I would do this in the OnMetadataCreated event in the custom attribute, however I cannot see how to add to the ModelValidator collection, only get them via GetValidators...
Anyone have any ideas?
Thanks in advance,
Dave
Rather than adding a custom attribute, you want to inject a validator based upon a condition.
You can use the class I detail in this answer to inject your validator based upon the conditions in your CMS.

ASP.NET MVC 3 validation order

As part of our ASP.NET MVC3 project, we have implemented some custom validation. On a particular entity e.g. UniqueMandatoryCode, we have got [Required] and our [CustomValidationDataAnnotation].
They both work but I would like to know what is happening under the hood in terms of the order of execution for validation. The issue I have is that our CustomValidation code is hit before the [Required] validation. This poses problems when we pass empty values.
So the question is, how do I control the order of validation i.e. first go through the [Required] validation and then the [CustomValidationDataAnnotation] validation.
I guess the validation order cannot be easily controlled.
The common technique is to ignore the empty/unspecified case in all other validators (ignore = you treat it as valid). You will anyway add a required validator if the value is mandatory that will handle that case. If the value is optional, why would you apply the custom validation rule on an empty/unspecified value?

Can I use MVC validation attributes within a custom model binder?

I have lots of MVC validation attributes on my model. Everything works great when the defaultModelBinder binds my model on submit. But, I need to create a custom modelbinder. I'd like to continue using my validation attributes. Can I? If so, how?
I'm not sure whether this is possible or not, but one thing I can say is that if it is possible then the extension points for default model binder don't make it very discoverable. I spent several hours one day trying to get this to work to no avail.
In lieu of getting this to work, you can use the Controller's TryValidateModel() methods.

Resources