[CLOSED] Range data annotation not working with Textfiled

  1. #1

    [CLOSED] Range data annotation not working with Textfiled

    Hi,

    Mine is a Asp.Net MVC Razor view application.

    Following is model

    public class ForValidation
    {
    [Range(1, 100, ErrorMessage = "Invalid range")]
    public decimal? AmtColumn { get; set; }
    }
    Following is my view

    <script>
     var validate = function (btnSub) {
                var form = btnSub.up('form');
                if (form.isValid()) { }
                else
                    return false;
                return true;
            };
    </script>
    
    @(Html.X().FormPanel()
    .ID("pnlAddRecord")
    ...
    ...
    Html.X().TextFieldFor(m => m.AmtColumn)
    ...
    ...
     .Buttons(
     Html.X().Button()
    .ID("btnSubmit")
    .DirectEvents(de =>
                        {
                            de.Click.Url = (Url.Action("ActionMethodName", "ControllerName"));
                            de.Click.EventMask.ShowMask = true;
                            de.Click.Before = "return validate(this)";
                            de.Click.FormID = "pnlAddRecord";
                        })
    )
    ...
    ...
    The issue I am facing is -> range validation is not working for textfield. But if I use a Numberfield as shown in the following url it works. http://mvc.ext.net/#/Models/Data_Annotations/

    My requirement is to use a textfield.

    Kindly provide inputs for the above.

    Thanks.
    Last edited by Daniil; Mar 21, 2014 at 1:56 PM. Reason: [CLOSED]
  2. #2
    Hi @PriceRightHTML5team,

    Well, a TextField doesn't support the Range validation.

    Please clarify why you cannot use a NumberField.
  3. #3
    Hi Daniil,

    Thanks for the reply.

    using NumberField range validation worked.

    So as to make a numberfield look as textfield and avoid numberfield default events (like mouse wheel updown) I have set the following properties.

     Html.X().NumberFieldFor(m => m.AmtColumn).HideTrigger(true).KeyNavEnabled(false).MouseWheelEnabled(false)

Similar Threads

  1. [CLOSED] Data annotation validation in form
    By MTSI in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 05, 2013, 2:04 PM
  2. Replies: 5
    Last Post: Dec 06, 2012, 3:42 PM
  3. Data annotation& validation sample
    By nurkmez in forum 2.x Help
    Replies: 1
    Last Post: Nov 24, 2012, 6:57 PM
  4. [CLOSED] ext:StoreParameter set value how get in textFiled
    By boris in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 15, 2012, 8:57 AM
  5. [CLOSED] Disabled TextFiled does not show data in Chrome
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 24, 2008, 8:45 AM

Tags for this Thread

Posting Permissions