[CLOSED] TextField converts value to int, but when starts with zero becomes null

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] TextField converts value to int, but when starts with zero becomes null

    Hello, I get a buggy behavior in TextField and I don't know how avoid it.
    I choose a TextField in order to put a string value in it, but if the value could be parsed to number it will be serialized as number.

    Moreover (from bad to worse) there is another point which makes the control unusable; when its value starts with "0" or the "+" sign, the value won't be posted.
    The control should contain phone numbers...

    TextFieldWithLeadingZeros.cshtml

    @page
    @model ExtCookbook.Pages.TextFieldWithLeadingZerosModel
    @{
    }
    <ext-section target="Main">
        <ext-container region="Center" scrollable="true" paddingAsString="30 20 30 50">
            <content>
                <h1>TextField converts to int</h1>
                Try the different behavior typing "123" first, and then "0123".
                <ext-container id="MainContainer" model="Model.MainContainer">
                </ext-container>
            </content>
        </ext-container>
    </ext-section>
    TextFieldWithLeadingZeros.cshtml.cs
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Threading.Tasks;
    using Ext.Net;
    using Ext.Net.Core;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    
    namespace ExtCookbook.Pages
    {
        public class TextFieldWithLeadingZerosModel : PageModel
        {
            public FieldContainer MainContainer { get; set; }
    
            public void OnGet()
            {
                MainContainer = new FieldContainer()
                {
                    Anchor = "100%"
                };
                MainContainer.Items.Add(new TextField()
                {
                    Id = "phoneNumber"
                });
                var btn = new Button()
                {
                    Text = "Click me"
                };
                btn.DirectEvents.Click.Method = HttpMethod.POST;
                btn.DirectEvents.Click.Url = $"?handler=ClickMeButtonClick";
                btn.DirectEvents.Click.ExtraParams.Add(new DirectEventParameter() { Key = "phoneNumber", Value = "App.phoneNumber.value", Mode = ParameterMode.Raw });
    
                MainContainer.Items.Add(btn);
    
            }
    
            public IActionResult OnPostClickMeButtonClick(JsObject jObj)
            {
                if (jObj.GetValueOrDefault("phoneNumber") == null)
                    this.X().Toast($"Posted value is null");
                else
                {
                    var postedValue = jObj.GetValueOrDefault("phoneNumber").Value.ToString();
                    this.X().Toast($"Posted value is {postedValue}");
                }
    
                return this.Direct();
            }
        }
    }
    Checking with the developer console what contains App.phoneNumber.value the string value is correct.

    help!
    Last edited by fabricio.murta; Sep 15, 2021 at 4:12 PM.

Similar Threads

  1. Replies: 2
    Last Post: Jun 29, 2014, 8:17 PM
  2. Replies: 6
    Last Post: May 29, 2013, 8:22 AM
  3. Replies: 3
    Last Post: May 10, 2013, 11:24 AM
  4. Replies: 10
    Last Post: Jul 31, 2012, 12:25 PM
  5. [1.0] Error binding null Int fields
    By protactinium in forum 1.x Help
    Replies: 1
    Last Post: May 07, 2010, 6:23 PM

Posting Permissions