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

How to validate a number field which must be integer?

5 Answers 1680 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick Wu
Top achievements
Rank 1
Nick Wu asked on 08 Apr 2012, 04:06 PM
there is a number field name "SiteHits". For this field ,I define validation as below:
validation:{
required:true,
min:1,
digits:true
}

I also include jquery(version 1.7.1) and jquery-validate(version 1.9.0).
it seems "digits" is not useful.

Does the problem cause by jquery ?
OR
Does KendoUI not support "digits" validation?

Hope the solution for it, thanks!

5 Answers, 1 is accepted

Sort by
0
Nick Wu
Top achievements
Rank 1
answered on 09 Apr 2012, 04:38 AM
A temporary solution is setting a NumericTextBox with  "{decimals:0}" to field editor.   :-(
0
Igor
Top achievements
Rank 2
answered on 24 Jun 2012, 02:39 AM
Nick,

could you please provide the source of your solution?
0
Nick Wu
Top achievements
Rank 1
answered on 26 Jun 2012, 07:47 AM
I just initialize the NumericTextBox instance with {decimals:0, format : "{0:n0}" , //other configuration...} .

With 'decimals:0' , dot which be input into textbox will be ignored. 
With 'format:''{0:n0}"', the value will be shown as integer .  ('format:"#" and 'format:"n0"' will get same result.)

The solution do not validate user's input , just control user's input. :-)
But I really think this is not a good idea !   Because I can't put this validation logic in model, so I must put this logic in view.
0
Igor
Top achievements
Rank 2
answered on 26 Jun 2012, 09:11 AM
Thanks for the answer!
dont you know if the same validation thing will work for kendo grid same way?
0
Nick Wu
Top achievements
Rank 1
answered on 27 Jun 2012, 08:07 AM
in my last reply, I said my solution just do more bit to control user's input in view , it's not a validation.
In fact, it seems there is no  validation rule for number type about "decimals".
Like offical example on "Editing Custom Editor", in my solution, I custom the field's editor using NumbericTextbox which configured with {"decimals:0",...}.

I find another post about custom validation, see below:
http://www.kendoui.com/forums/framework/validation/unable-to-get-custom-validation-working-on-a-grid.aspx
maybe it's more better, but I have no time to do it.  ;-)
Tags
Grid
Asked by
Nick Wu
Top achievements
Rank 1
Answers by
Nick Wu
Top achievements
Rank 1
Igor
Top achievements
Rank 2
Share this question
or