DateTime conversion to User Timezone - Odoo Website - odoo-10

I'm trying to display datetime field value in odoo website , it works using t-field and t-field-options inside span,
but i need to show as editable field in form inside input field, how to show field datetime to user timezone in input value.

you can use JavaScript
<field id="user_date" name="date" />
<script>
document.getElementById("user_date").innerHTML = Date();
</script>

Related

Form validation in vuelidate

I am doing form validations in vuelidate. I have a date picker in my form which is not a mandatory field. Yet I cannot submit the form without selecting a date from the date picker. How is it so? Can anyone tell me how to fix it? I want to keep the date picker field as not a mandatory field. Here is my code:
<v-menu ref="menu3" :close-on-content-click="false" v-model="anniversaryVisibility" :nudge-right="10" :return-value.sync="enquiryForm.anniversary"
lazy
transition="scale-transition"
offset-y
full-width
min-width="290px">
<v-text-field
slot="activator"
v-model="enquiryForm.anniversary"
label="Anniversary"
append-icon="event"
outline
readonly
:error-messages="fieldErrors('enquiryForm.anniversary')"
#input="$v.enquiryForm.anniversary.$touch()"
#blur="$v.enquiryForm.anniversary.$touch()"
>
</v-text-field>
<v-date-picker v-model="enquiryForm.anniversary" #input="$refs.menu3.save(enquiryForm.anniversary)"></v-date-picker>
</v-menu>
Can I see the stuff inside the <script> tags?
I'm assuming inside you have something like this
validations: {
fields: {
anniversary: required
}
}
So you would have set anniversary to required, you just need to delete it.

Filter Kendo Grid column with Date picker

I have a Kendo MVC Grid that has a column with a DateTime column. Everything looks good and formats correctly. When i filter, it gives me a date picker and a time picker. When i remove the DateTimeFilter Template below and use template contains, it will give me a Date picker (which i want), but still wants to filter by the date and time.. Is there a way i can have the date and time all as the same field, but only filter with a Date picker.? Example: i use the Date picker to pick 07/24/2017 and it filter everything on that date regardless of time.. Or do they need to be completely different fields, or even concatenated fields in the same column.?
the Column data looks as such: 07/24/2017 18:12:00
columns.Bound(c => c.CreatedDate).Title("Submitted On")
.ClientTemplate("#= kendo.toString(kendo.parseDate(CreatedDate), 'MM/dd/yyyy HH:mm:ss') #")
.Filterable(ftb => ftb.Cell(cell => cell.Template("DateTimeFilter")));
If you're using MVC, in your model, you add DataType.Date above your DatePicker property as below:
[DataType(DataType.Date)]
public DateTime SubmittedOn{ get; set; }
Note: add reference to System.ComponentModel.DataAnnotations if its not included in your header.

kendo datepicker change event doesn't refresh the month view

I have a kendo date picker defined as follows:
<input id="datePicker" data-format="dd.MM.yyyy" data-month='{ "content": "<span class=\"#= dateRange.hasReport(data.date) ? \"boldDate\" : \"normalDate\" #\">#=data.value #</span>" }' data-role="datepicker" data-bind="value: new Date(), events: {change: dateChanged}" style="width:150px;" />
In the month template, I bold some dates depending on whether there is a report or not for that date by a call to the method dateRange.hasReport(data.date)
Now, there is an external event which causes the daterange to change. I want to now refresh the calender view so that the dateRange.hasReport is called for all dates again.
I am unable to find a way to do this.
Any ideas?
Use the methods min(), max() to change your ranges and the 'change' event will be triggered I guess. You can bind your function there if you want.
http://docs.kendoui.com/api/web/datepicker
I fixed it by destroying the element and recreating it again
$("#datePicker").data("kendoDatePicker").destroy();
$('#datePicker').empty();
createDatePicker(); //Creates the datepicker widget again
$("#datePicker").closest("span.k-datepicker").width(150);

How to integrate Telerik DatePicker date format validation with Webforms ValidationSummary

The Telerik DatePicker does not support the WebForms CompareValidator's data type check, because when an invalid date is entered, the DatePicker shows an error style on the input box, but returns an empty value. So on a data entry form with optional date fields, some method is required to handle invalid dates so that they do not appear on postback to be empty fields.
By using a CustomValidator, we can check if the DatePicker has a value in the input text box but returns an empty string - this indicates the date format is invalid.
function DateValidate(sender, args) {
var datepicker = document.getElementById(sender.controltovalidate).control;
var dateInput = datepicker.get_dateInput();
args.IsValid = !(dateInput.get_textBoxValue() != "" && dateInput.get_value() == "");
}
<telerik:RadDatePicker
ID="RetiredDatePicker" dbSelectedDate='<%# Bind("RetiredDate") %>' Runat="server">
</telerik:RadDatePicker>
<asp:CustomValidator
ID="RetiredDateValidator" runat="server" CssClass="Error"
ClientValidationFunction="DateValidate" ValidateEmptyText="true"
ControlToValidate="RetiredDatePicker" SetFocusOnError="True"
ErrorMessage="Retired date is not a valid date">*</asp:CustomValidator>

mvc how to use annotation with input tag

Hi I am using MVC 3 with Razor, I am using the below code.
I need to know whether I can use Annotations with this input tag?
<input type="text" id="#endDateName" name="#endDateName" value="#String.Format("{0:MM/dd/yyyy}", endDateValue)" />
I need annotation to check whether a proper date time value has been entered and not any random text.
Thanks in advance
After some help from Amyz,
I have used date picker now, and yes it does not allow characters like a,..z,!##, and so on.
But the problem is it does allow a date like say 02/1212312321/1231231313 this is what I want to prevent now the same can be seen on http://jqueryui.com/demos/datepicker/
Its better to handle this at client side only: for that you can use date picker:
Date Picker
or you can use data annotation like:
[DataType(DataType.Date, ErrorMessage = "Please enter a valid date (ex: 2/14/2011)")]
public DateTime DateTime { get; set; }
The final step is to register the adapter in our global.asax file:
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(DataTypeAttribute), typeof(DataTypeAttributeAdapter));

Resources