ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Awe.TextBoxFor - new strange behavior in 4.9
Title:
B
I
{code}
?
just discovered new strange behavior on TextBoxFor with placeholder. I have string field returning MM.YYYY value. TextBoxFor formats the value as MM,YYYY and throws validation error due to comma. After correction to "." everything is ok and the value goes to db without problems. I call the record again and TextBoxFor formats the value again as MM,YYYY. (tried .Numeric(false) already - no change) and in 4.7 everything worked ok! view code: <div class="form-group"> @Html.LabelFor(model => model.PurchaseDate, new { @class = "control-label col-md-2" }) <div class="col-md-12" style="width:140px"> @(Html.Awe().TextBoxFor(model => model.PurchaseDate).Placeholder("MM.JJJJ").HtmlAttributes(new { @class = "form-control" })) @Html.EditorFor(model => model.PurchaseDate, new { htmlAttributes = new { @class = "form-control" } }) </div> </div> the second EditorFor displays the text correctly viewmodel: public class Test { public string MyProperty { get; set; } } controller: public ActionResult Test() { Test vm = new Test(); vm.MyProperty = "12.2015"; return View(vm); }
Save Changes
Cancel
TT Tom
asked at 17 Nov 2015
the validation is not done by textbox, it's defined by the server side data annotations on the viewmodel and enforced in the controller or on the client side by jquery.validate plugin; now the textbox has a format func option which if you're using means what is being displayed and the actual value may differ; you can also try using using a simple Html.Textbox instead and see if you get the same problem
at 17 Nov 2015
Omu
not the validation causes this behavior. The format the Awe.TextBoxFor is displaying text is wrong. Html.TextBox displays the value in right form MM.YYYY
at 17 Nov 2015
TT Tom
you can edit the questions, and after comment to let men know
at 17 Nov 2015
Omu
BTW - german culture
at 17 Nov 2015
TT Tom
using the code you've provided I can't get any errors, anything wrong; you could try to create a mini demo of the problem http://aspnetawesome.com/learn/mvc/CommonProblems#Isolate-the-problem
at 17 Nov 2015
Omu
took the latest demo and modified Controller for TextBoxDemo public ActionResult Index() { TextBoxDemoInput tbi = new TextBoxDemoInput(); tbi.Name = "12.2010"; return View(tbi); } output is 12,2010 not 12.2010
at 17 Nov 2015
TT Tom
Seems to be a problem with german culture. When I switch region to England the format is displaying in MM.YYYY, when i switch to german MM,YYYY - it's a string variable !!!
at 17 Nov 2015
TT Tom
same code in 4.7 works ! Also with german region settings
at 17 Nov 2015
TT Tom
4.7 textbox is almost the same as using Html.Textbox(.., new { placeholder = "text" })
at 17 Nov 2015
Omu
ok, it's a bug, the decimal separator gets replaced regardless if it's numeric or not, should be replaced only when it's numeric; will let you know, until then you can use a simple textbox
at 17 Nov 2015
Omu
ok thanks! I give a try with the old assembly. It's a little bit urgent, have deployment for test tomorrow :)
at 17 Nov 2015
TT Tom
if you're not using the numeric extension you could just use Html.Textbox and for placeholder set htmlattributes new { placeholder = "text" }
at 17 Nov 2015
Omu
Perfect! Thank you!
at 17 Nov 2015
TT Tom
this has been fixed, you can redownload it from your profile now
at 23 Nov 2015
Omu
Answers
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK