Hi,
It looks like NumberSpinner widget use constraints to limit property values on client side, but the constraints are not send from the server. The IntegerEditorDescriptor has only parameterless constructor:
public IntegerEditorDescriptor() : base((object) int.MinValue, (object) int.MaxValue) { }
I also think that this is strange....
If you need to use values of range property, then you could prepare new editor descriptor that inherits IntegerEditorDescriptor and setup the Min/Max correctly. It's just few lines of code:
[EditorDescriptorRegistration(TargetType = typeof(int), UIHint = "CustomInteger")] [EditorDescriptorRegistration(TargetType = typeof(int?), UIHint = "CustomInteger")] public class CustomIntegerEditorDescriptor : IntegerEditorDescriptor { public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes) { base.ModifyMetadata(metadata, attributes); var rangeAttribute = attributes.OfType<RangeAttribute>().FirstOrDefault(); if (rangeAttribute != null) { var constrains = this.EditorConfiguration["constraints"]; this.EditorConfiguration["constraints"] = new { min = rangeAttribute.Minimum, max = rangeAttribute.Maximum, places = (string)constrains.GetType().GetProperty("places").GetValue(constrains), exponent = (bool)constrains.GetType().GetProperty("exponent").GetValue(constrains) }; } } }
Then use CustomInteger UiHint on your property and it should work.
Hi,
Thanks for the answer!
Actually you only have to do this (did some (a lot) try and error yesterday), (Here you see the int? that you answered on yesterday ;) ). For some reason it's enough just to register your descriptor and it will understand that you want to send your Range-data annotaition.
[EditorDescriptorRegistration(TargetType = typeof(int?), UIHint = "myOptionalProp")] public class EditorSelectionEditorDescriptor : EditorDescriptor { public EditorSelectionEditorDescriptor() { } }
I guess the title needs some explination. I have a property of type int. I have set the range attribute like this "[Range(1,5)]" and declared my own dijit to be used. The dijit is called but without the correct range values. It looks like this. (console.log(this)) inside the dijit javascript)
constraints: Object
exponent: false
max: 2147483647
min: -2147483648
places: "0,0"
The error message on the other hand looks like this
invalidMessage: "Fältet Points99 måste vara mellan 1 och 5."
which means
invalidMessage: "The property Points99 must be between 1 and 5."
Has anyone seen this before, is it a bug or a feature? Thanks for the help and discussion!