Is there a reason or bug that "constraints" isn't populated with ocrrect vlaues in the dijit context?

Vote:
 

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!

#133855
Sep 12, 2015 13:38
Vote:
 

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.

#133860
Sep 12, 2015 19:17
Vote:
 

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()
{

}
}



#133862
Edited, Sep 13, 2015 7:43
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.