how to validate datefield before select in extjs 3.4 - date

i am using extjs 3.4 add add datefield in portal for selection of date range.Start date and end date means if i select 28 jan 2014 in start date then i want to validate end date after 28 jan 2014 is display with in 30 days interval only .
and i also want to validate difference between start date and end in only 30 days
{
id:'funnelStartId',
xtype: 'datefield',
format : 'd-M-Y',
editable:false,
emptyText:'Start date',
listeners:{
select: function (value,date){
getFunnelDateRange()
}
}
},{
id:'funnelEndId',
`enter code here` xtype: 'datefield',
format : 'd-M-Y',
editable:false,
emptyText:'End date',
listeners:{
select: function (value,date){
getFunnelDateRange()
}
}
}

I think you may be able to get a similar behavior to the one you describe by setting the min and max values of the datefield on select:
var dateValidate = function() {
var dateFld1 = Ext.getCmp('funnelStartId');
var dateFld2 = Ext.getCmp('funnelEndId');
startValue = dateFld1.getValue();
endValue = dateFld2.getValue();
maxEndValue = startValue.add(Date.DAY, 30);
if (endValue < startValue || endValue > maxEndValue) {
dateFld2.setValue(null);
}
dateFld2.setMinValue(startValue);
dateFld2.setMaxValue(maxEndValue);
}
I have a created fiddle demonstrating.

Related

SAPUI5 - How to search formatted date from table

I have a date column with format MMM d, yyyy. If user searches "2018", how can I filter it?
XML
<table:Column filterProperty="StartDate" sortProperty="StartDate" width="100px" tooltip="{i18n>ttStartDate}">
<Label text="Start Date"/>
<table:template>
<Text text="{path:'localModel>StartDate',formatter:'.formatter.date'}"/>
</table:template>
</table:Column>
Controller
searchTable: function (evt) {
var oTable = this.getView().byId("ordersTable");
var searchTerm = evt.getParameter("query");
if (searchTerm === "") {
//When clear was pressed on search field
oTable.getBinding("rows").filter(null);
} else {
var filters = [];
var outerFilters = [];
var searchTerms = searchTerm.split(" "); //words separated by space are considered as separate search terms.
for (var k = 0; k < searchTerms.length; k++) {
filters.push(new Filter("OrderType", sap.ui.model.FilterOperator.Contains, searchTerms[k]));
filters.push(new Filter("StartDate", sap.ui.model.FilterOperator.Contains, searchTerms[k]));
outerFilters.push(new Filter(filters));
filters = [];
}
oTable.getBinding("rows").filter(new Filter({
filters: outerFilters,
and: true //Default is OR between filters
}));
}
},
Date received as : StartDate: Sat Mar 23 2019 05:30:00 GMT+0530
Date formatted as: Mar 23,2019
I am aware that 'Contains' works only for Strings but how to make it work for date also
We faced a similar issue and there were 2 solutions,
One on the client side and another on the server side.
Client side:
Use a formatter on that property to parse the date to a string.
Server side:
Ask for another property that is that date as a string.
Looking at your code I can see you are already using a formatter (formatter.date) so we can explore the client side option.
In your formater.date function you can do something like this:
date(yourDateField)
{
let options = { year: 'numeric', month: 'short', day: 'numeric' };
return yourDateField.toLocaleDateString("en-US", options);
}

Free jqGrid restoring date with custom formatter after cancelling inline edit

After inline edit is cancelled, the date column comes back as undefined instead of restoring the original value. Column is defined as following (dates are coming in 1970-01-01 format):
{name:'Release<br>Date',index:'Street_Date', sorttype:"date", width:70,
formatter: function (cellvalue, options, rowObject) {
return cellvalue === ('1970-01-01') ? "" : $.fn.fmatter.call(this, "date", cellvalue, options, rowObject);
},
formatoptions: {newformat:'d M y'},
editable:true,
editoptions: {
size:9,
dataInit: function(el, options) {
$(el).datepicker({
dateFormat: "d M y",
defaultDate: '01 Jan 70',
onSelect: function(dateText, inst) {
}
});
}
},
searchoptions: {
sopt: ['eq','ne','ge','le'],
dataInit: function (elem) {
$(elem).datepicker({ showButtonPanel: true, dateFormat: 'yy-mm-dd' })
}
}
},
The inline edit is setup as following:
ondblClickRow: function (rowid) {
var savedRows = $grid.jqGrid("getGridParam", "savedRow");
if (savedRows.length > 0 && savedRows[0].id !== rowid) {
// cancel editing
$grid.jqGrid("restoreRow", savedRows[0].id);
}
if (savedRows.length === 0) {
$grid.jqGrid("editRow", rowid, editOptions);
}
}
When Grid is loaded, the date shown like 07 Aug 18, entering the inline editing by double click, the date is still 07 Aug 18. After cancelling the edit either by clicking away or clicking Cancel button, date becomes NaN undefined N. After refresh, it comes back correctly though.
How to preserve the correct date after cancelling editing?
Grid behaves correctly with formatter: date
free jqGrid v jqGrid 4.13.5
Maybe the author of free-jqGrid will help better, but I would recommend you to add additional parameter (action='edit') when the formatter is called. Code below:
formatter: function (cellvalue, options, rowObject) {
return cellvalue === ('1970-01-01') ? "" : $.fn.fmatter.call(this, "date", cellvalue, options, rowObject, "edit");
},
Note the last parameter in $.fn.fmatter.call
UPDATE
This is working in my tests.
Since you use a custom date fomatter it is needed the value in savedRows to be unformated in order to be saved correct. In case of default formatter = date this is done automatically.
Below is the code that can be used, suppose you know the index of the field in colModel:
ondblClickRow: function (rowid) {
var savedRows = $grid.jqGrid("getGridParam", "savedRow");
if (savedRows.length > 0 && savedRows[0].id !== rowid) {
// cancel editing
savedRows[0].Release_Date = $.unformat.date.call($grid[0], savedRows[0].Release_Date, $grid[0].p.colModel[1]);
$grid.jqGrid("restoreRow", savedRows[0].id);
}
if (savedRows.length === 0) {
$grid.jqGrid("editRow", rowid, editOptions);
}
}

DatePicker NativeBase - Format of the picked date

I am using DatePicker of NativeBase and want to change the format of the displayed date after picking a date. I am unable to find a relevant prop due to lack of docs.
Is there a way I could change the format of the date as in DatePickerAndroid using format="YYYY-MM-DD"?
Fixed in native-base v2.6.1 onwards.
<DatePicker
formatChosenDate={date => {return moment(date).format('YYYY-MM-DD');}}
..... />
Try this:----
async onPressAction() {
try {
const {action, year, month, day} = await DatePickerAndroid.open({
// Use `new Date()` for current date.
// May 25 2020. Month 0 is January.
date: new Date(2018, 6, 26)
});
if (action !== DatePickerAndroid.dismissedAction) {
// Selected year, month (0-11), day
var date = new Date(year, month, day);
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
console.log('>>>>>>>>>>>>>'+year);
console.log('>>>>>>>>>>>>>'+month);
console.log('>>>>>>>>>>>>>'+day);
console.log(year+'-'+month+'-'+day);
}
} catch ({code, message}) {
console.warn('Cannot open date picker', message);
}
}

DOJO Grid Date Text box shows 1970 when user deletes the date

I am new in DOJO grid. I have a grid which have multiple Date Boxes under project Start date for each user. When admin selects one date (e.g. user1 Start Date) and moves on to other field (e.g. description) and comes back and deletes the date (user1 Start Date) it shows 1 Jan 1970. I used formatter and changed the display, but when I submit date then its showing 1 Jan 1970 as selected date. How can I set it for Blank Value? If user deletes the date I want to show Blank value there. How am I suppose to achieve this?
Code I use is as follows
smallLayout.push({
field : editableFieldNames[index],
name : editableColumnNames[index],
sortable : true,
filterable : true,
autoComplete: true,
editable : true,
width : '100px',
styles : 'text-align: left; background:#A3C8EC; color: #000;',
type : dojox.grid.cells.DateTextBox,
constraint: {
datePattern : "dd MMM yyyy",
selector : "date"
},
formatter: formatDate
});
// Formatter to return date in correct format
var formatDate = function (val, rowIdx, cell) {
//dijit.byId('myid').reset();
cell.customClasses.push('noBackgroundClass');
if (val != '0000-00-00' && val != null) {
// If date is comming from database
if (typeof val == 'string') {
return "<div class = 'editableCell'>" + val + "</div>";
} else {
console.log(cell);
if (val.getFullYear == '1970') {
return "<div class = 'editableCell'><div>";
}
return "<div class = 'editableCell'>"
+ val.getDate() + ' '
+ month[val.getMonth() + 1] + ' '
+ val.getFullYear() + "</div>"
;
}
} else {
return "<div class = 'editableCell'><div>";
}
}
Thank You,
Amit

How can I query for dates with Node.js and Mongoose?

I have:
dates = {}
today = new Date()
todayminus7days = new Date(today).setDate(today.getDate()-7)
dates.startDate = todayminus7days
dates.endDate = today
query =
person_gender: filter.gender if filter.gender
person_age:
0:
$gte: dates.startDate
1:
$lte: dates.endDate
However, when I run this query through a Mongoose model, the end query is:
{ person_gender: 'female',
person_age:
{ '0': { '$gte': 1317055089524 },
'1': { '$lte': Mon, 03 Oct 2011 16:38:09 GMT } } }
and this returns null results within that date range.
How can I pass Date's to Mongoose then?
Your problem here is not MongoDB or Mongoose related, but in your assumption that .setDate() returns a Date (which it doesn't).
If you change your initialization code to:
...
todayminus7days = new Date(today);
todayminus7days.setDate(-7);
...
It should work as expected.