I have the following code:
<input data-role="datepicker" data-bind="value:referralData.Referral.from_date" />
With the value to bind as such:
from_date: "2014-01-01T00:00:00"
In the object and it doesn't bind anymore.
I have tried:
<input data-role="datepicker" data-bind="value:referralData.Referral.from_date, parseFormats:'YYYY-MM-DD\Thh:mm:ss'" />
But it states that: Uncaught Error: The parseFormats binding is not supported by the DatePicker widget. So I believe I have a syntax error that I am missing.
Does anyone know how to tell the datepicker to pick up this date?
data-bind is for live-binding options. If all you want to do is use the configuration option, you can use data-parse-formats:
<input data-role="datepicker"
data-parse-formats="YYYY-MM-DDThh:mm:ss"
data-bind="value:referralData.Referral.from_date" />
Also, if you want to use a 24 hour clock, you should use the this formatting config for time: HH:mm:ss
The solution by #Lars works, but the date format specifier is wrong (as of Kendo version 2014.3.119). It should be yyyy-MM-ddTHH:mm:ss (lower case for year and day and upper case for hour):
<input
data-role="datepicker"
data-bind="value:referralData.Referral.from_date"
data-parse-formats="yyyy-MM-ddTHH:mm:ss" />
And as a completion, if sometimes you need to, you can in fact pass more than one format, according to the documentation, like this:
<input
data-role="datepicker"
data-bind="value:referralData.Referral.from_date"
data-parse-formats="['yyyy-MM-ddTHH:mm:ss','yyyy-MM-dd']" />
You can create a custom binding for date format:
Custom Binding
kendo.data.binders.widget.dateFormat = kendo.data.Binder.extend({
init: function (widget, bindings, options) {
//call the base constructor
kendo.data.Binder.fn.init.call(this, widget.element[0], bindings, options);
},
refresh: function () {
var that = this,
value = that.bindings["dateFormat"].get(); //get the value from the View-Model
$(that.element).data("kendoDatePicker").setOptions({
format: value
}); //update the widget
}
});
HTML
<div id="report1" data-role="view" data-model="APP.models.report1">
<input data-role="datepicker" data-bind="value: start_date, dateFormat: date_format" />
</div>
Model
window.APP = {
models: {
report1: kendo.observable({
start_date: new Date(),
date_format: "dd/MM/yyyy",
}),
}
};
var app = new kendo.mobile.Application($(document.body), {
initial: "report1",
skin: "default",
});
Related
I have user_feedback in repeatable component in user table, how can I upload image to the newly added user feedback in strapi v3.
What currently I am doing
const data = await strapi.services["users"].update(
{ id: id },
{
...updatedData,
}
);
const newFeedback =
data.feedback_prototype_phase[data.feedback_prototype_phase.length - 1];
await strapi.entityService.uploadFiles(data, files, {
id: data.id,
model: "user.user_feedback",
field: "image",
});
Edited this answer, Its best to
Upload the image to Media-Folder, via http://localhost:1337/api/upload
Then use the same URL http://localhost:1337/api/upload and include this in your request as the doc says in https://docs.strapi.io/developer-docs/latest/plugins/upload.html#examples
<form>
<!-- Can be multiple files if you setup "collection" instead of "model" -->
<input type="file" name="files" />
<input type="text" name="ref" value="api::restaurant.restaurant" />
<input type="text" name="refId" value="5c126648c7415f0c0ef1bccd" />
<input type="text" name="field" value="cover" />
<input type="submit" value="Submit" />
</form>
<script type="text/javascript">
const form = document.querySelector('form');
form.addEventListener('submit', async (e) => {
e.preventDefault();
await fetch('/api/upload', {
method: 'post',
body: new FormData(e.target)
});
});
</script>```
Your ref-id will be the ID of your entry, by entry It means the ID of your table's row or in no-sql you would say your document id.
Your ref is your service name as it suggests, your table name per say
Your field is the name of the field of the entry you want to upload the media too
Your files is simple the files that you want to upload
I would highly recommend you to use the template code given on docs then modify it, Instead of working on it directly. Thats what I did.
I'm working in laravel and I want to show in my Bootstrap Datepicker field a date in a format (dd/mm/yyyy) but I want to store it in format (yyyy/mm/dd).
are there some property in Datepicker to do that? this is my input:
<div class="form-group">
<label for="fecha_nac"></label>
<input type="text" class="form-control CalendarioDP"
name="fecha_nac" placeholder="Colocar fecha"
value="{{ Carbon\Carbon::now()->formatLocalized('%d/%m/%Y') }}">
</div>
My Script:
<script>
$('.CalendarioDP').datepicker({
format: "dd/mm/yyyy",
language: "es",
});
</script>
When I let the format in script like this way, the date is showed it and stored it in a format (dd/mm/yyyy),
Showed it in the input field
Stored it in the DB, is the first date
but I want it in (yyyy/mm/dd).
I have used "Torzer DateTime Mutator" and "protected $dates" but I want to know if there are exist a simple DaterPicker property to declaret just once in the script and not to specify each field that I want to Convert like in Torzer.
put this in your controller
public function Store(Request $request)
{
//here put you format date to store in your DB
$object->date = \Carbon::createFromFormat('d/m/Y', $request->fecha_nac)->format('Y/m/d');
}
Try this.
<script>
$('.CalendarioDP').datepicker({
dateFormat: 'yyyy-mm-dd',
language: "es",
});
</script>
Or update your input type into this.
<input type="text" id="CalendarioDP" data-date-format='yyyy-mm-dd'>
//this is my html code where i have a datepicker component wheer i want to throw a validation but i want the error message to be shown once the user leaves this feild and go on some other inputfeild of the form
<datepicker v-model="present_complaint.experienceSince"
name="date" placeholder=24-july-1994>
</datepicker>
<span class="error-msg" v-show="present_complaint.experienceSince ==''">
Date is a mandatory field
</span>
//this is my js code
present_complaint:{
description:'',
}
//currently when the page loads by default the error message is there on the datepicker as by default it is empty now i want that it should only be diaplayed when user clicks on it and leave it not selecting any date basically when it goes to any other feild and not selecting any date
I have a solution for you.
<div id="app">
<input type="text" placeholder="type something" v-model.trim="text" #blur="blur">
<span v-show="text === ''">Please Fill the input</span>
</div>
new Vue({
el: "#app",
data: {
text: null
},
methods: {
blur() {
if(this.text === null) {
this.text = ''
}
}
}
})
The answer it is simplified to understand the logic.Once you do,you can solve your problem by replacing some code.Take a look to the demo
I'm trying to customize my use of the Kendo UI kendoScheduler widget. I'm specifying a custom template for the editable window that pops up when you go to add/edit an appointment in the scheduler, like so:
editable: {
template: $("#editor").html()
},
I'm defining the template like this:
<script id="editor" type="text/x-kendo-template">
<h3>Edit Appointment</h3>
<p>
<label>Patient: <input name="title" /></label>
</p>
<p>
<label>Start: <input data-role="datetimepicker" name="start" /></label>
</p>
</script>
So now I want to add a Kendo UI DropDownList and configure it to populate from a remote datasource. How do you configure such things within a template?
Sample code (does not work):
<p>
<label>Type: </label><input id="appointmentTypeDropDownList" />
</p>
# var dataSource = new kendo.data.DataSource({ transport: { read: { url: "http://demos.kendoui.com/service/products", dataType: "jsonp" } } });
# $("#appointmentTypeDropDownList").kendoDropDownList({ dataSource: dataSource, dataTextField: "ProductName", dataValueField: "ProductID" } ) ;
The error it gives with the above code is:
Uncaught Error: Invalid template:'
Probably this is just a script encoding issue; I'm more interested in the proper way to place a bound DropDownList inside of a template.
Update - The latest simplified version of what I'm trying to do is available at this jsfiddle URL. The goal is simply to bind the dropdown list in the most straightforward way possible. Thanks!
If you move your scheduler DataSource into your viewModel you can use the parenting functionality of a kendo Observable to have the DropDownList bind against the correct DataSource.
var viewModel = new kendo.observable({
appointmentTypes : new kendo.data.DataSource({
data: [{
id: 1,
text: "Wellness Exam"
}, {
id: 2,
text: "Diagnostic Exam"
}, {
id: 3,
text: "Nail Trim"
}]
}),
schedulerData: [{
id: 1,
start: new Date("2014/1/27 08:00 AM"),
end: new Date("2014/1/27 09:00 AM"),
title: "Breakfast"
}]
});
Now when you create the scheduler you just have it use the schedulerData property on the view model, as the DataSource for the scheduler.
$("#scheduler").kendoScheduler({
...
dataSource: viewModel.schedulerData,
...
});
The last piece is just changing your DropDownList declaration to use the appointmentTypes property on your view model.
<select id="appointmentTypeDropDownList" data-bind="source:appointmentTypes, value:id" data-text-field="text" data-value-field="id" data-role="dropdownlist" data-autobind="true" />
Since your template will be bound against the Observable objects in the schedulerData DataSource, Kendo will climb the parent tree of the object until it's able to resolve the appointmentTypes property that's on viewModel.
The template throws an error because the selector "#appointmentTypeDropDownList" should be escaped and look like this "\\#appointmentTypeDropDownList" (Kendo UI Documentation).
After you fix this you won't receive template errors but it still doesn't bind the data to the KendoDropDownList.
I checked what a KendoUI MVC helper will render in this case and it seems that if your template looks like this, it will work.
<script id="editor" type="text/x-kendo-template">
<h3>Edit meeting</h3>
<p>
<label>Title: <input name="title" /></label>
</p>
<p>
<label>Start: <input data-role="datetimepicker" name="start" /></label>
</p>
<p>
<label>Start: <input data-role="datetimepicker" name="end" /></label>
</p>
<p>
<label>Type: </label><input id="appointmentTypeDropDownList" />
<script>
var dataSource = new kendo.data.DataSource({ transport: { read: { url: "http://demos.kendoui.com/service/products", dataType: "jsonp" } } });
jQuery(function() { jQuery("\\#appointmentTypeDropDownList").kendoDropDownList({ dataSource: dataSource, dataTextField: "ProductName", dataValueField: "ProductID" } ); });
<\/script>
</p></script>
It's not necessary to put any javascript in the template, you can use Kendo's data-attribute initialization features.
So, your template would look something like:
<label>Type: </label>
<input id="appointmentTypeDropDownList" data-text-field="ProductName" data-value-field="ProductID" data-bind="value:ProductID" data-source="dataSource" data-role="dropdownlist" data-autobind="true" />
Then you would have Javascript outside of your template:
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "http://demos.kendoui.com/service/products",
dataType: "jsonp"
}
}
});
As long as dataSource is defined globally, you're good to go. There's more info on data attribute initialization here http://docs.telerik.com/kendo-ui/getting-started/data-attribute-initialization
Edit: just noticed your comment "data will depend on the selected datetime". You could always try re-defining the datasource options in the edit event, which is called prior to displaying the popup editor window. I've not used this scenario, but I don't see why it wouldn't work.
I've a Kendo template and that template contains a textbox like below with datetime picker.
<script id="popup_editor" type="text/x-kendo-template">
<input data-role="datepicker" data-bind="value: datePickerValue" />
</script>
Now I want to set min value for this. i.e I don't want to permit to select previous days than today. Is an example available on the web?
Try this
var myDatePicker = $("#myDatePicker").kendoDatePicker().data("kendoDatePicker");
var today = new Date();
var day = today.getDate();
var month = today.getMonth() + 1;
var year = today.getFullYear();
myDatePicker.min(new Date(year,month,day));
Usually, you can do some javascript here:
var myDatePicker = $("#date").kendoDatePicker().data("kendoDatePicker");
myDatePicker.min(new Date());
but I'm not sure if it's going to work within your template that way. Maybe it's a start.
Ok I had to implement something similar recently and found a straightforward way to do this. I realize this is way too late, but I found this question, while I was doing my research.
Say the below is your template: (Simplified for brevity)
<div class="k-block k-shadow">
<p>Contract Start Date: </p>
<input type="text" tabindex="7"
class="k-input k-textbox"
name="Contract_Start_Date"
id="Contract_Start_Date"
data-bind="value:Contract_Start_Date"
data-format="MMMM yyyy"
data-start="year"
data-depth="year"
data-change="setContractMinEnd"
data-role="datepicker" />
</div>
<div class="k-block k-shadow">
<p>Contract End Date: </p>
<input type="text" tabindex="8"
class="k-input k-textbox"
name="Contract_End_Date"
id="Contract_End_Date"
data-bind="value:Contract_End_Date"
data-format="MMMM yyyy"
data-start="year"
data-depth="year"
data-role="datepicker" />
</div>
The below code for the Contract_Start_Date field assigns a JS function to the "Change" event of that field: data-change: setContractMinEnd
I added the above function in a script block to go out with the page. And now every time the start date is changed the end date gets a min value which is the start date:
function setContractMinEnd() {
var edval = $('#Contract_Start_Date').data("kendoDatePicker");
var sdval = $('#Contract_End_Date').data("kendoDatePicker");
if (sdval && edval) {
edval.min(sdval.value());
}
}
You can obviously get fancy with that logic and set the below or something to that effect: edval.min(new Date())
Hope it helps someone...
You can just pass data-min="your Date in proper format" in html input.
<script id="popup_editor" type="text/x-kendo-template">
<input data-role="datepicker" data-bind="value: datePickerValue" data-min="min_date_value" />
</script>
This will not even show dates beyond the minimum value.