I am trying to implement a dynamic start date for a bootstrap datepicker while using vuejs. Below is an example of what I have in my code currently. Using -30d or a date formatted as 01-01-2016, but not 2016-01-01 works.
<input type="text" name="cancelDate" id="cancelDate" autocomplete="off" class="form-control form-control-small"
v-model="sale.cancelDate"
v-bind:class="{ 'has-error': !validation.cancelDate }"
v-datepicker start-date="{{sale.saleDate}}" />
<p>{{sale.saleDate}}</p>
The {{sale.saleDate}} in the p tags is accessible, and displays a date like '1/27/2016'. Changing 'start-date' to 'data-start-date' does not work. In the datepicker directive, I have...
var self = this;
$(self.el).datepicker({
startDate: self.params.startDate,
endDate: self.params.endDate,
todayBtn: "linked",
autoclose: true
});
How can I get the start-date to appear dynamically?
I post an example here:
//script.js
new Vue({
el:"#app",
data:function(){
return {
startDate: moment().subtract(7, 'days').format('MM/DD/YYYY'),
cancelDate: moment().format('MM/DD/YYYY')
}
},
ready:function(){
$('.datepicker').datepicker({ startDate: this.startDate });
}
})
// index.html
<div id="app">
<input class="datepicker" type="text" v-model="{{cancelDate}}" value="{{cancelDate}}" >
</div>
https://jsfiddle.net/nosferatu79/jfk97gp9/4/
Hope this help...
Related
I am trying to show minDate:1 and defaultDate:+3 in datepicker.
$( ".datepicker1" ).datepicker({
dateFormat: "mm-dd-yy",
altFormat: "yy-mm-dd",
altField: "#altField",
minDate: 1
});
$("#TTOCutoffDate").datepicker("option", "defaultDate", 3);
$("#fileDate").datepicker("option", "defaultDate", 3);
If I use html input box, it works as expected.
<input type="text" name="fileDate" id="fileDate" class="datepicker1">
success picture
But If I use html.textboxfor as below, it doesn't work.
<%=Html.TextBoxFor(x => x.TTOCutoffDate, ttoEnabled ? new {#class="datepicker1" } : (object)new {
disabled = "disabled" })%>
TextBoxFor picture
It seems that default date is not set as default date.
How can I make it work with TextBoxFor?
html rendered as below.
<input type="text" name="fileDate" id="fileDate" class="datepicker1 hasDatepicker">
<input class="datepicker1 hasDatepicker" id="TTOCutoffDate" name="TTOCutoffDate" type="text" value="" readonly="" style="background-color: rgb(255, 255, 255);">
Thank you.
You're missing the fileDate ID
<div class="col-sm-8">
<i class="far fa-calendar-alt"></i>
<input
id="dtpFrom"
type="text"
placeholder="Datepicker"
placement="top"
class="form-control"
bsDatepicker
[bsConfig]="{dateInputFormat: 'DD MMM YYYY',containerClass: 'theme-blue'}"
[bsValue]="todayDate"
[minDate]="minDate"
[maxDate]="maxDate"
/>
</div>
import { BsDatepickerConfig } from'ngx-bootstrap/datepicker';
export class CardlessTransactionsComponent implements OnInit {
datePickerConfig: Partial<BsDatepickerConfig>;
privatetodayDate: Date = newDate();
minDate: Date;
maxDate: Date;
}
constructor(privatefb:FormBuilder) {
this.todayDate = newDate();
this.minDate = newDate();
this.maxDate = newDate();
this.minDate.setDate(this.minDate.getDate() - 7);
this.maxDate.setDate(this.maxDate.getDate() + 0);
at the HTML file, I think there is something need to do inside the bsValue while at the ts file, I have no idea where to change to get the output that I want which is to make it display the month's name instead of the month numeric value
You should get today's date through a formControl instead of outside it to get this working...
relevant HTML:
<div class="row">
<div class="col-sm-8">
<i class="far fa-calendar-alt"></i>
<input
id="dtpFrom"
placeholder="Datepicker"
placement="top"
class="form-control"
bsDatepicker
formControlName="dateMDY"
[bsConfig]="{dateInputFormat: 'DD MMM YYYY',containerClass: 'theme-blue'}"
[bsValue]="todayDate"
[minDate]="minDate"
[maxDate]="maxDate"
/>
</div>
</div>
working stackblitz here
Thanks for the suggestions, i have already figure it out. (make changes at the TS file)
initializeForm () {
this.cardlessForm= this.fb.group ({
dateFrom:new Date(),
dateTo:new Date ()
});
}
I just add the 'new Date ()' at the dateFrom and dateTo then i removed the code ( this.maxDate.setDate(this.maxDate.getDate() + 0);
I put a new datepicker into a admin page and it lets me select the date needed but when I had data-date-format="yyyy/mm/dd" as dd/mm/yyyy, it would not save the date in the database and would save it as 0000-00-00 so I changed the format to data-date-format="yyyy/mm/dd" and it works now and saves the date correctly now in the database but is there any way I can have the date format as dd/mm/yyyy in the input field as it currently shows as 2019/10/22
The code I have is below
<div id="exstdate" class="col-lg-6 input-group date" data-date-format="yyyy/mm/dd">
<input type="text" class="form-control" name="exstdate" value="<?php echo $exstdate; ?>" id="exstdate" readonly />
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span><div class="error alert-danger"></div>
</div>
<script>
$(function () {
$("#exstdate").datepicker({
language: "en",
autoclose: true,
todayHighlight: true,
dateFormat: 'dd/mm/yyyy'
}).datepicker('update', new Date());
});
</script>
I'm pretty much at wit's end with this now, Trying to build an application that tracks hours for timesheets, The logic so far all works all the calculations seem right for hours but for whatever reason the form is creating 2 objects when it's submitted and i have absolutely zero idea why.
Here's what gets outputted to console on form submit, The data's all correct and lines up with what's in the form but it's duplicated, and i have absolutely no idea why;
day-app.component.ts:44 Object {date: "2016-08-08", startTime: "09:00", endTime: "17:30", client: "qwe", project: "qwe"…}
day-app.component.ts:44 Object {date: "2016-08-08", startTime: "09:00", endTime: "17:30", client: "qwe", project: "qwe"…}
Day.ts - Object for holding the data for each day logged
export class Day {
id: number;
date: Date;
startTime: Date;
endTime: Date;
hours: number;
client: string;
project: string;
task: string;
}
Day.service.ts - The class used to store incoming data
import { Injectable } from '#angular/core';
import { Day } from './day';
#Injectable()
export class DayService {
lastId: number = 0;
public days = [];
addDay(day): void {
this.days.push(day);
}
Day-app.component.ts - The component used to render the views and forms and send form data onto the Day Service for storage
import { Component } from '#angular/core';
import { DayService } from '../day.service';
import { Day } from '../day';
#Component({
moduleId: module.id,
selector: 'app-day-app',
templateUrl: 'day-app.component.html',
styleUrls: ['day-app.component.css'],
providers: [DayService],
})
export class DayAppComponent {
constructor(private dayService: DayService) {
}
// Can access methods from DayService;
// dayService.method
// formService.method
get days() {
return this.dayService.getAllDays();
}
onSubmit(form): void {
let formData = form;
let timesTotal = (formData.startTime-formData.endTime*24);
let startDate = new Date(Date.parse(formData.date + " " + formData.startTime));
let endDate = new Date(Date.parse(formData.date + " " + formData.endTime));
let timeDiff = (((endDate.getTime()-startDate.getTime())/3600)/1000);
let newDay = {
date : formData.date,
startTime : formData.startTime,
endTime : formData.endTime,
client : formData.client,
project : formData.project,
hours : timeDiff
};
console.log(newDay);
this.dayService.addDay(newDay);
}
}
Day-app.component.html
<form #f="ngForm"
(ngSubmit)="onSubmit(f.value)"
class="form">
<div class='input-group'>
<div class='row'>
<div class='col-sm-12 col-md-12'>
<div class='col-sm-6 col-md-6'>
<label>Date to add</label>
<input type='date'
name='date'
placeholder='What date did you work?'
class='form-control'
ngModel />
<br />
<label>Client</label>
<input type='text'
name='client'
placeholder='Which client were you working for?'
class='form-control'
ngModel />
<br>
</div>
<div class='col-sm-6 col-md-6'>
<div class='row'>
<div class='col-sm-6 col-md-6'>
<label>Clocked In</label>
<input type='time'
name='startTime'
placeholder='Punch in time'
class='form-control'
ngModel />
</div>
<div class='col-sm-6 col-md-6'>
<label>Clocked Out</label>
<input type='time'
name='endTime'
placeholder='Punch out time'
class='form-control'
ngModel />
</div>
</div>
<label>Project</label>
<input type='text'
name='project'
placeholder='Which project were you working on?'
class='form-control'
ngModel />
</div>
</div>
<hr />
</div>
</div>
<br>
<input class='btn btn-sm btn-success' autofocus="" type='submit' value='Add Day' />
</form>
using this code
<input type="text"
id="StudentDOB"
class="controls span2"
data-bind="datepicker: StudentDOB"
name="StudentDOB" />
yeilds the following result.
When I change the code to
<input type="text"
id="StudentDOB"
class="controls span2"
data-bind="datepicker: StudentDOB, datepickerOptions: {}"
name="StudentDOB" />
It appears as follows:
Now I want the year and month option while setting my max year to 2014. How do I do this?
The date picker you are talking about is not the the knockout datepicker as there is no such thing. It's the jQueryUI datepicker. The options are in the api documentation on the jQueryUI website: http://api.jqueryui.com/datepicker/
datepickerOptions: { changeYear: true, changeMonth: true, yearRange: '1900:2014' }
http://jsfiddle.net/d4kkg/