DateRangePicker display date-range-key instead of date on selected - forms

How to display date-range-key instead of date except Custom Range? eg: Display "Yesterday" not "2022-12-13 - 2022-12-13" on selected/apply. But i still want to use the actual date value for form submission. Maybe i can put the actual date on hidden input. But again how to dislay date-range-key? eg: Yesterday, Last 7 Days, This Month, etc.
Form
<input type="text" class="form-control" placeholder="" aria-label="purchaseTime" aria-describedby="basic" name="dateFilter" id="dateFilter" value="{{ $datesFilter }}" readonly>
Script
$(function() {
$('input[name="dateFilter"]').daterangepicker({
"autoApply": true,
ranges: {
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(7, 'days'), moment().subtract(1, 'days')],
'Last 30 Days': [moment().subtract(30, 'days'), moment().subtract(1, 'days')],
'This Month': [moment().startOf('month'), moment().subtract(1, 'days')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
"maxDate": moment().subtract(1, 'days'),
"alwaysShowCalendars": true,
opens: "left",
locale: {
direction: "ltr",
format: 'YYYY-MM-DD',
// separator: " ~ ",
}
});
});

Related

Getting asynchronous values from ant-design vue form using onValuesChange

I have a form that submits and send data to the backend using ant-design-vue. However, what I would like to achieve is give the user some form of feedback so while they type in the field they get to see the value {fullname placeholder} updated immediately, and clicking on the submit button sends it to the backend altogether.
{{ fullname || 'Your Name' }}
<a-col :xs="{ span: 24 }" :lg="{ span: 12 }">
<a-form-item label="Full Name">
<a-input
type="text"
placeholder="Your Name"
:disabled="toggleEdit === 'edit'"
v-decorator="[
'fullname',
{
initialValue: this.fullname || '',
rules: [{ required: true, message: 'Name is required!' }],
},
]"
autocomplete="name"
/> </a-form-item
></a-col>
So the {{ fullname }} at the top updates immediately the user types Similar to v-model. But I would like to know how I can achieve this in ant-design-vue form with the onValuesChange method.
You need to use v-model to bind your value on inputfirstly.
meanwhile, use #click on button with submit method
<a-input
type="text"
v-model="inputValue" <---here
placeholder="Your Name"
:disabled="toggleEdit === 'edit'"
v-decorator="['fullname',
{
initialValue: this.fullname || '',
rules: [{ required: true, message: 'Name is required!' }],
},
]"
autocomplete="name"/>
<button #click="submit"></button>
...
data(){
return{
inputValue: ""
}
}
methods:{
submit(){
// I send keyword with a object which include this inputValue by POST method
// you can change it to yours, and keyword as well
fetch("api-url").post({ keyword: this.inputValue })
.then(response.json())
.then(res => { //dosomthing when you get res from back-end })
}
}
Does above code is your requirement?

jquery date picker extension library

This code snippet runs fine here as just a snippet, but when we add it to the cart the date picker and calender is are both not visible and inspecting in chrome we see:
Uncaught TypeError: $(...).datepicker is not a function
at theme.js?v=5845886865919317655:5165
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
const unavailable = {
dates: ["2020/12/1", "2020/11/25", "2020/11/26", "2020/11/27", "2020/12/11", "2020/12/12", "2020/12/24", "2020/12/25", "2020/12/26", "2020/12/27", "2020/12/31", "2021/1/1"],
days: ["Saturday", "Monday", "Friday", "Sunday"],
};
$("#dateDiv").datepicker({
inline: true,
altField: '#dateInput',
minDate: '+2',
maxDate: '+18',
beforeShowDay: function(date) {
const ymd = date.getFullYear() + "/" + ("0" + (date.getMonth() + 1)).slice(-2) + "/" + ("0" + date.getDate()).slice(-2);
const day = date.getDay();
if ($.inArray(ymd, unavailable.dates) < 0 && $.inArray(days[day], unavailable.days) < 0) {
return [true, "enabled", "Book Now"];
} else {
return [false, "disabled", "Booked Out"];
}
},
onSelect: function(dateText) {
$('#dateInput').val(dateText);
}
});
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<div>
<label for="date">Pick a delivery date:</label>
<input hidden id="dateInput" type="text" name="attributes[date]" required autofocus/>
<div id="dateDiv"></div>
<span class="instructions">We currently ship corals Monday...</span>
</div>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

Materialize datepicker SelectOnClose not working

I'm trying to create a datepicker with Materialize.
According to the documentation the datepicker should close when the user selects a date.
That's not working in my page. I'm using the latest Chrome browser on Windows. I've tried IE browser, but there's the whole datepicker not showing...
Click here for my page (input 3 and 4 are datepickers)
My javascript:
$('#due_date').pickadate({
monthsFull: [ 'januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december' ],
monthsShort: [ 'jan', 'feb', 'maa', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec' ],
weekdaysFull: [ 'zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag' ],
weekdaysShort: [ 'zo', 'ma', 'di', 'wo', 'do', 'vr', 'za' ],
today: 'vandaag',
clear: 'verwijderen',
close: 'sluiten',
firstDay: 1,
format: 'dd-mm-yyyy',
formatSubmit: 'yyyy/mm/dd',
closeOnSelect: true,
selectMonths: true, // Creates a dropdown to control month
selectYears: 3, // Creates a dropdown of 15 years to control year
min: new Date()
});
Can anyone help me to fix these datepickers?
Please add below few lines to your code..
onSet: function (ele) {
if(ele.select){
this.close();
}
}
var datePicker = $('.datepicker').pickadate({
onSet: function () {
this.close();
}
});
The developer of materialize thought that it would match Google's date picker if it doesn't close on select according to this issue:
https://github.com/Dogfalo/materialize/issues/870
However you can change the source code of materialize if you don't mind, like this:
https://github.com/Dogfalo/materialize/commit/db0629d30a9d3e5ac06a019955a8e10062f91833
Better Solution: Use if ( 'select' in arg ) condition so that the datepicker dialog wont hide when you select month or year.
$('.datepicker').pickadate({
onSet: function( arg ){
if ( 'select' in arg ){ //prevent closing on selecting month/year
this.close();
}
}
});
i had the same problem and i solved it this way:
$('.datepicker1').pickadate({
selectMonths: true, // Creates a dropdown to control month
selectYears: 15, // Creates a dropdown of 15 years to control year
min: true,
onOpen: function () {
this.clear();
},
onSet: function () {
var x,y,year,date,month;
x = $('.datepicker1').pickadate().val().toString();
y = x.split(/[ ,]+/);
date = y[0];
month = y[1];
year = y[2];
console.log(y[0]+" "+ y[1]+ " "+ y[2]);
if(date && month && year){
this.close();
}
}
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Materialize Datepicker</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/css/materialize.min.css">
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js"></script>
</head>
<body>
<form class="col s6">
<label for="To" >To : </label>
<input type="date" id="To" class="datepicker1">
</form>
<script src="site.js"></script>
</body>
</html>
The onSet: function(called when a date is set) ensures the date,month and year are entered and closes only if the date is set.
The onOpen: function(called when the datepicker opens) clears the input when datepicker is opened again, useful in case when the user inputs the wrong date.. Without using this function , the datepicker cant navigate though different months,years without closing..
Hope this solves your problem.
If "closeOnSelect: true" is not working then you can call click event of the close button
HTML code for input element:
<input type='text' id='purchase_date'/>
Js code for the element:
jQuery(document).ready(function(){
$('#purchase_date').pickadate({format: 'yyyy-mm-dd'})
.on('change', function(){
$(this).next().find('.picker__close').click();
});
});
Hope this will solve your problem.
Tested on materializecss 1.0.0: use onSelect callback
$('.datepicker').datepicker({
autoClose: true,
today: 'Today',
clear: 'Clear',
close: 'Close',
format: 'dd/mm/yyyy',
//perform click event on done button
onSelect: function () {
$('.confirmation-btns .datepicker-done').click();
}
});

Datepicker MinDate maxDate, maxDate = datestart + 3 months

Using the basic two input field datepicker format.
http://jqueryui.com/datepicker/#date-range
Input1:
$(function() {
$("#DATE_START").datepicker({ showOtherMonths: true, minDate: +1, dateFormat:"yy-mm-dd", });
});
Input2:
$(function() {
$("#DATE_END").datepicker({ showOtherMonths: true, changeMonth: true, changeYear: true, minDate: +2, dateFormat:"yy-mm-dd", });
});
Issue:
I want the DATE_END to be DATE_START input value, plus 3 months.
EX: maxDate = DATE_START + '3m'
Not needed current date plus 3 months
Thanks
You have just to set the Date like this:
$(function() { $("#DATE_START").datepicker({ showOtherMonths: true, minDate: "+3m", dateFormat:"yy-mm-dd", }); })
$( "#DATE_END" ).datepicker.datepicker({ showOtherMonths: true, minDate: "+3m", dateFormat:"yy-mm-dd", }); })
Have a look on the documentation. Its pretty good.
http://api.jqueryui.com/datepicker/#option-minDate
You can also use this to set the date:
$( ".selector" ).datepicker( "setDate", "10/12/2012" );

Highchart / Highstock theme for all charts (here french format)

I spend a lot of time to format each highcharts elements to french format (texts, dates, buttons, etc..)
I propose a little "macro" french theme for your applications using highcharts.
Highcharts.theme = {
lang: {
/*------ Dates translation ------ */
months: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin',
'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
weekdays: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi',
'Jeudi', 'Vendredi', 'Samedi'],
shortMonths: ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Juin', 'Juil',
'Aout', 'Sept', 'Oct', 'Nov', 'Déc'],
/*------ Texts translation ------ */
downloadPNG: 'Télécharger en image PNG',
downloadJPEG: 'Télécharger en image JPEG',
downloadPDF: 'Télécharger en document PDF',
downloadSVG: 'Télécharger en document Vectoriel',
exportButtonTitle: 'Export du graphique',
loading: 'Chargement en cours...',
printButtonTitle: 'Imprimer le graphique',
resetZoom: 'Réinitialiser le zoom',
resetZoomTitle: 'Réinitialiser le zoom au niveau 1:1',
printChart: 'Imprimer le graphique',
/*------ Number Formate ------ */
thousandsSep: ' ', // ex: 52 000
decimalPoint: ',' // ex: 1 525,50
},
credits: {
/*------ Unrelated but usefull to remove credits in each charts ------ */
enabled: false
},
rangeSelector: {
/*------ Highstock date range selector (the 2 little inputs in right corner) ------ */
inputDateFormat: '%e %b %Y', // ex: 8 Avr 2014
inputEditDateFormat: '%d/%m/%Y', // After clicking on item ex : 13/06/2014
// Processing After enter key pressed : apply the 13/06/2014 format
inputDateParser: function (value) {
value = value.split('/');
return Date.UTC(
parseInt(value[2]),
parseInt(value[1]) - 1,
parseInt(value[0])
);
},
/*------ Highstock zoom selector (on the left top side) ------ */
buttons: [{
type: 'month',
count: 1,
text: '1 M' // useless translate :p
}, {
type: 'month',
count: 6,
text: '6 M' // useless translate :p
}, {
type: 'year',
count: 1,
text: '1 A' // translate Y in A (Année in french)
}, {
type: 'all',
count: 1,
text: 'Tout' // translate all in Tout
}],
selected: 2, // Here we force to select 6 M
inputEnabled: true // Active Inputs
},
};
Highcharts.setOptions(Highcharts.theme);
You have to add this file(charts-theme.js) between the highstock.js and your .highcharts function.
<script src="http://code.highcharts.com/stock/highstock.js"></script>
<script src="http://saur/assets/backend/pages/scripts/charts-theme.js"></script>
<script src="http://saur/assets/backend/pages/scripts/charts.js"></script>
Obviously, you can use it with different language, or just to define some "general" uses.
Hope it help.