Decimal Validation and Binding conflict when french

20 views
Skip to first unread message

Rémi BOURGAREL

unread,
Jan 25, 2012, 10:52:39 AM1/25/12
to Castle Project Development List
Hi All
I have this model

public class MyViewModel{
[ValidateDecimal]
public decimal ADecimal{get;set;}
}

And this view

$FormHelper.NumberField("myobject.ADecimal")

If myobject.ADecimal is equal to "13.6"

The input will have "13,6" for value (note the comma).
But this value is not passing the Prototype validation.

And if you enter "13.6" in the input the prototype validation is OK
but after the posting myobject.ADecimal is 0 without raising a
validation error on the server side.

Possible Solutions :

- Overriding the prototype number validation so it works with "," (and
every other culture)
- Or forcing the use of "." as separator (ie forcing the culture when
you display the input tag and when you parse the content)

hammett

unread,
Jan 25, 2012, 4:56:54 PM1/25/12
to castle-pro...@googlegroups.com
Is the current thread uiculture set to french?

2012/1/25 Rémi BOURGAREL <bourgar...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "Castle Project Development List" group.
> To post to this group, send email to castle-pro...@googlegroups.com.
> To unsubscribe from this group, send email to castle-project-d...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/castle-project-devel?hl=en.
>

--
Cheers,
hammett
http://hammett.castleproject.org/

Rémi BOURGAREL

unread,
Jan 26, 2012, 3:18:58 AM1/26/12
to Castle Project Development List
Yes it is, I'm sorry I posted my thread and I didn't finish the title.

On Jan 25, 10:56 pm, hammett <hamm...@gmail.com> wrote:
> Is the current thread uiculture set to french?
>
> 2012/1/25 Rémi BOURGAREL <bourgarel.r...@gmail.com>:

hammett

unread,
Jan 26, 2012, 2:33:55 PM1/26/12
to castle-pro...@googlegroups.com
Could you step in the code and see whether we are overriding the
conversion code with an InvariantCulture or so? That'd be the only
explanation for the misbehavior..

2012/1/26 Rémi BOURGAREL <bourgar...@gmail.com>:

Rémi BOURGAREL

unread,
Jan 27, 2012, 8:45:50 AM1/27/12
to castle-pro...@googlegroups.com
You don't override it :

 protected static string FormatIfNecessary(object value, IDictionary attributes)
        {
            var formatString = CommonUtils.ObtainEntryAndRemove(attributes, "textformat");

            if (value != null && formatString != null)
            {
                var formattable = value as IFormattable;

                if (formattable != null)
                {
                    value = formattable.ToString(formatString, null);
                }
            }
            else if (value == null)
            {
                value = String.Empty;
            }

            return value.ToString();
        }

the second parameter of toString is "null", so you're using the current UICulture : French so you logically display decimal with a comma, but client side validation will fail :

IsNaN("1,4")

Will return false.

hammett

unread,
Jan 27, 2012, 12:02:39 PM1/27/12
to castle-pro...@googlegroups.com
oh well, I dont even remember how we implemented the client side
validation. You should check the js lib used.

2012/1/27 Rémi BOURGAREL <bourgar...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Development List" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/castle-project-devel/-/3GkIvya2jeQJ.

Reply all
Reply to author
Forward
0 new messages