triina / FunForFisherman

1 stars 0 forks source link

DateTime #4

Closed Nonse closed 6 years ago

Nonse commented 10 years ago

Couldn't find the solution for creating a new Fishing Session with the current date set as default in the model. Currently it has the default value for the date field (01.01.0001). I've tried to make the DateTime.Now in both conctructor and annotation and it shows current date. But it doesn't allow me to create the new Fishing Session showing the error message "The field date must be a date." Googled this problem, nothing works.

eugene-doe commented 10 years ago

Do you want the date selection to be available to user, i.e. can it be something different from the current date? If yes, I think there's no need to set it in the controller, set it in the view instead.

BTW, MVC renders @Html.EditorFor(model => model.date) as <input type="datetime">, which is only supported by Safari and Opera: http://www.w3schools.com/html/html5_form_input_types.asp So in Opera I see a date picker, while other browsers show me a simple textbox. I think we should use the jQuery UI datepicker for consistency. Will give it a try now.

eugene-doe commented 10 years ago

Updated the Create view, check it out. It looks like the entire file has been replaced, but the actual changes are in the Scripts section and this line: @Html.TextBoxFor(model => model.date).

The default value flashes for half a second in IE (not in other browsers) before being replaced by the current date. Don't know if it's possible to get rid of it completely. Things would be easier if we used a string and not DateTime in the app, but I'm not sure if it's possible with Database First in MVC.

And the reason why dd.MM.yyyy is not accepted is the same stupid jQuery validator that was causing troubles with decimals. It doesn't recognize anything but / as the date separator.