bbros
Sep 13, 2021, 11:12 AM
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!
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!