How to disable “the error the value ‘abc’ is not valid for IntegerProperty” - asp.net-mvc-3

I hope someone can help me out to disable the default validation that MVC 3 runs when I post a string value in an integer field. Currently the application will add the error “the value ‘abc’ is not valid for IntergerProperty” to the ModelState before our validators are executed.
We don’t use client side validation and have our own validators that are loaded in the Global.asax. We only want to use these validators to check the input and would like to disable this check.
Is it possible to disable this behavior?
Thanks in advanced,
André

I think the best solution for your issue is to implement a custom model binder to override the default behavior if you really want/need to be able to take alpha chars in a numeric field.

Related

Symfony2 validation filters

In my Symfony 2 application I need to filter input before passing it on to validation [1], however, I can't seem to find any system within Symfony to do this.
The type of filtering I looking for is e.g. to be able to filter a dash out of a specific field before validating it. E.g. users can enter 123-123 but the only accepted value is 123123. Just as I can set up validation rules with constraints, I'm looking for something similar for filters.
[1] http://symfony.com/doc/current/book/validation.html
Nifr's answer is good but is missing of an important alternative that, if I understand correctly your question, seems to fit perfectly your needs.
You can use a hook that is pretty much an event listener: if something happens or is going to happen, it intercepts the event and redirect it to your function.
In this case, you need a PRE_BIND hook (is deprecated since 2.3 version, now it's called PRE_SUBMIT)
Read this if you need help about
Either write your own Validation Assert to filter and then proxy the other validators for this purpose ...
... or one or multiple Regex Asserts.
... or use a DataTransformer to transform/filter the input.
With the DataTransformer involved you could aswell consider creating a new FieldType which renders two inputs with a seperator like the date form-field does. ( if not not used with widget => single_text )

How to explicitly validate a knockoutJs observable

I'm using KnoockoutJS and the validation plugin from here, https://github.com/ericmbarnard/Knockout-Validation.
By default, validation messages only appear after a field has been modified. The problem is that when the user clicks "Save", I need to validate the bound observable regardless of whether the user has modified the field or not.
I can't seem to find a .Validate()on an obervable...
Looks like ko.validation.validateObservable might be what you're looking for... I didn't test it, but that looks like it.
I use ko.validatedObservable($data)().isValid() to get whether the viewmodel is false or not.
If there is somebody who knows a better way, please leave a comment :)

Yii: How do you abort model validation in the middle, after one of the rules returns FALSE?

In Yii framework, how do you abort any further validation after one of rules returns FALSE ?
What I am trying to achieve is:
1) stopping unnecessary MySQL queries after we know that a model didn't pass the validation.
2) cleaner, easy to understand error messages for the web user, without sorting them manually in the controller.
Thank you in advance for your help!
In short: there is no global setting or solution: If you look at CActiveRecord::validate(), you can see all validators are called and executed.
You can prevent running multiple validations for the same attribute. You would have to set skipOnError=true for all the validation rules.
http://www.yiiframework.com/doc/api/1.1/CValidator/#skipOnError-detail
whether this validation rule should be skipped when there is already a
validation error for the current attribute. Defaults to false.
I think a global option could be added to Yii (quite easily actually).
Thank you!
For users browsing this thread:
The validate() method - to be extended in your custom AR class - is located in yii/framework/base/CModel, line 150.

How do you validate an archetype field that is not required, but if you give it, you should validate?

Products.validation has some validators (like regex) that I would like to use in some non required fields.
So, the use case is: The validation is required, but only if the field is not empty.
How do you do it? I know I can create a custom validator, check the REQUEST and do all the magic, but this seens wrong to me: I should avoid creating custom code since I should just register the RegexValidators from Products.validation and use it. I tried to understand V_SUFFICIENT and register a regex validator using it, but isn't applicable to my situation.
I couldn't find anything on the internet, on mailing lists, on nabble, etc. So, how do you validate your fields that aren't required, but if the user provides something, you then need to validate?
I need this in a Plone 3.3.5 instance.
You can use required = False and your desired validators:
http://plone.org/documentation/manual/developer-manual/archetypes/fields/fields-reference#common-field-attributes

Remote Validation with MVC3

I've just been reading the article on MSDN about remote validation. This is great, but it only shows validating a specific property value.
Is there a way I can pass other values from my model into the validation for a particular property? For example, let's say that a user wants to cancel a number of items off an order - they should be prevented from entering a figure greater than the original order amount.
Thanks
No, you can't.
Brad Wilson:
At this time, only property level
validators can emit client-side
validation (as that lines up much
better with the idea of input
validation in the form of the
browser... there is no "model" to
speak of, from the browser's point of
view).
Stuart Leeks:
I don't believe you can hook up client
validation with IValidatableObject
Well, i am nit sure if you mean this, but you can use AdditionalFields with your RemoteValidation attribute.
Remote Validation in ASP.Net MVC 3: How to use AdditionalFields in Action Method

Resources