I am trying to use Monotouch Dialog reflection API to bind to a class.
I have the following in my class:
[Entry("Birth Date")]
public DateTime BirthDate;
When this renders, it renders as a DateTime, which I suppose it expected.
Is there anyway to force this to be a date only
Thanks,
Steve
Should have read the documentation.
You can get a Date only selection by decorating the field with
[Date] instead of [Entry(....
Related
I'm using a DateTimePicker with vaadin flow 23.0.5.
The problem is that if a user only enters either the date or time (but not both), then when I save the field using a binder the result is a null LocalDateTime.
import com.vaadin.flow.component.datetimepicker.DateTimePicker;
private DateTimePicker noticeTwoDateTime;
noticeTwoDateTime = new DateTimePicker(label);
layout.add(field);
binder.forField(this.noticeTwoDateTime).bind(
NoticeTemplate::getNoticeDateTwo,
NoticeTemplate::setNoticeDateTwo);
Is there some way to warn the user that they must enter both?
I've explored using a validator but it only gets passed the LocalDateTime which of course is null.
First of all you can use a helper text as described here:
https://vaadin.com/docs/latest/ds/components/date-time-picker/#providing-input-guidance
And if that's not enough you can try to create your own validation routine and use it within the binder as e.g. here:
https://vaadin.com/docs/latest/flow/binding-data/components-binder-validation/#defining-validators
Could look similar to this then:
myDateTimeBinding = binder.forField(myDateTimePicker)
.withValidator(myDateTime -> Validation.validateDateTime(atdDateTimePicker.getValue()),
"Please pick Date and Time")
.bind(......
with Validation as your Validation Utils Class and validateDateTime as your method returning a boolean.
Workaround: If you mark the field as being required/mandatory then the DateTimePicker shows an error message, if one of both is missing.
Yeah sure, you don't want mark every date/time as required....
This problem seems to have existed already in Vaadin 14: Vaadin 14 DateTimePicker with optional time or warning for missing time
I have a property of my model as follows:
[DisplayName("Manufactured Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DateManufactured { get; set; }
In my scaffolded MVC Core view I have this code to display that value:
<input asp-for="LiftingItem.DateManufactured" class="form-control" />
In Chrome, the input shows the text "dd/mm/yyyy" and I get the error:
The specified value "09/02/2006" does not conform to the required
format, "yyyy-MM-dd".
Whereas in IE I get the actual date (e.g. "09/02/2006"). I think that difference is because Chrome is using the HTML 5 Date type input and so requires the format in "yyyy-MM-dd" format to display it?
If I remove the DisplayFormat attribute, sure enough it works in Chrome, but then in IE the date is in the wrong format ("yyyy-MM-dd" instead of "dd/mm/yyyy").
So, it seems like using DisplayFormat with a non "yyyy-MM-dd" format stops the Tag Helpers working? Is there any way to get it working nicely for both HTML 5 compatible and older browsers?
PS: I've also tried applying the formatting in the view instead using asp-format="{0:dd/MM/yyyy} as described in this question, but that also stops it working in Chrome.
Edit: I could also remove [DataType(DataType.Date)], but then I don't get the built in datepicker on HTML5 compatible browsers, which I would definitely like to on mobile devices.
Yes, you can combine the Tag Helpers with the DisplayFormat data annotation.
So, it seems like using DisplayFormat with a non "yyyy-MM-dd" format stops the Tag Helpers working? Is there any way to get it working nicely for both HTML 5 compatible and older browsers?
Just remove [DataType(DataType.Date)] from your model and the DisplayFormat(..) statement will start working as expected.
PS: I've also tried applying the formatting in the view instead using asp-format="{0:dd/MM/yyyy} as described in this question, but that also stops it working in Chrome.
You can combine the DisplayFormat(..) data annotation with the asp-format tag helper if you should require, in a specific view, a different date format than the one specified in your model.
If you have the following property in your model:
[DisplayName("Manufactured Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DateManufactured { get; set; }
and a view (a Detail view for instance) with the following line of code:
#Html.DisplayFor(model => model.DateManufactured)
Then you application will display dates having a format corresponding to the one specified with the data annotation, i.e. {0:dd/MM/yyyy}. Here's an example: 23/02/2017.
If you add in another view (an Edit view for instance) the following line of code (please note that I've added a 'M' to the month format):
<input asp-for="LiftingItem.DateManufactured" asp-format="{0:dd/MMM/yyyy}" class="form-control" />
Then the asp-format will take precedence over the model's data notation and your application users could type dates like this one: 23/Feb/2017 in the input box.
In my Web Application i have changed my dijit/form/DateTextBox date format using constraints="{datePattern:'MM/dd/yyyy'}" attribute,
But when i call the form containing the dijit/form/DateTextBox using domForm.toJson the format is changed to yyyy/dd/MM
why?
How to solve it
Dijit/Form/DateTextBox is a dojo/widget not dom.
domForm.toJson access Dom's value not Dijit widget's get('value') function which gives you a formatted output as you expect.
To get correct value - Use Dijit/Form and then use form.get("value")
Dijit Form
I am trying to make datetime picker readonly. I found the following code in the internet
$("#RequestedDate").attr('disabled', true)
.next("span.t-select")
.children("span.t-icon-calendar").css("visibility", "hidden");
which works great but it reset datetime to minimun datetime.
You want to set the "readonly" attribute, not "disabled". If it's disabled the value won't be picked up.
I am trying to develop a WebGrid with dropdownlist, where by default the selected value http://www.mikesdotnetting.com/Article/202/Inline-Editing-With-The-WebGrid
//code in Controller (which grabs more than 1 set of data):
ViewBag.material_codes = new SelectList(db.Master_Material, "material_code", "material_code");
//code in View(WebGrid):
grid.Column("material_code", MenuItemModel.translateMenuItem("MaterialCode"), format:
#<text>
#Html.DropDownList("material_code", (SelectList)ViewBag.material_code, item.material_code)
</text>),
However I get the error:
Error 1 'System.Web.Mvc.HtmlHelper<IMv3.ViewModels.RMReceivingViewModels>' has no applicable method named 'DropDownList' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
I believe it is caused by "item.material_code", any idea guys?
Extension methods (such as the DropDownList) cannot contain dynamic parameters. So you need to cast the item.material_code to its underlying type:
#Html.DropDownList(
"material_code",
(SelectList)ViewBag.material_code,
(string)item.material_code
)
Here I cast it to string but if the underlying type is different you should adjust your code.