JQuery Datepicker : Month and Year repopulating - styles

This is my code
1.Click the datepicker and change month or year.
2.Now input field modified.
3.Close the datepicker and again click the datepicker modified value not setted in datepicker.
Please help this issue.
$( "#monthYearOnly" ).datepicker({
buttonImage: "../images/calendar.png",
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
showOn: "both",
dateFormat: 'yy/mm',
maxDate : '0d',
defaultDate: '1d',
constrainInput: false,
buttonText: 'Click to show the month',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
$("#monthYearOnly").focus(function (year, month, inst) {
var test = $("#monthYearOnly").val();
$(".ui-datepicker-calendar").hide();
$("#ui-datepicker-div").position({
my: "center top",
at: "center bottom",
of: $(this)
});
});
});
I am using three three datepicker in single jsp page
Two datepicker with calendar and another one without calendar(only month and year)

You can introduce a beforeShow.
Your datepicker can look as follows:
$("#monthYearOnly").datepicker({
buttonImage: "../images/calendar.png",
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
showOn: "both",
dateFormat: 'yy/mm',
maxDate: '0d',
defaultDate: '1d',
constrainInput: false,
buttonText: 'Click to show the month',
onClose: function (dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
},
beforeShow: function() {
var dateText = $(this).val();
var isPopulated = dateText.length > 0;
if (isPopulated) {
var selectedDate = $.datepicker.parseDate("yy/mm/dd", dateText + "/01");
$(this).datepicker("option", "defaultDate", selectedDate);
$(this).datepicker("setDate", selectedDate);
$(this).datepicker("refresh");
}
},
});
I believe this will get you what you are trying to achieve.

Related

How to compare two dates and give condition as per the selected dates on two date Fields in suitelet script?

Here what I am doing is I have just created a simple suitelet as well as linked client script also,
The thing is here I'm getting an error page called unexpected error. I don't know why it is going there. Im providing both scripts please take a look and give me a solution.
define(['N/record','N/ui/serverWidget','N/redirect','N/runtime','N/search','N/url'],function(record,serverWidget,redirect,runtime,search,url){
function onRequest(context){
var Request = context.request;
var Response = context.response;
var name = context.fieldId;
if(Request.method == 'GET') {
var form=serverWidget.createForm({title:"Customer entry Suitelet"});
var primaryinfo=form.addFieldGroup({
label:'Primary Information',
id:'custpage_advs_primary_info',
});
var firstname=form.addField({
label:'First Name',
id:'custpage_advs_first_name',
type:serverWidget.FieldType.TEXT,
container:'custpage_advs_primary_info'
});
firstname.isMandatory=true;
var lastname=form.addField({
label:'Last Name',
id:'custpage_advs_last_name',
type:serverWidget.FieldType.TEXT,
container:'custpage_advs_primary_info'
});
Response.writePage(form);
form.clientScriptModulePath = './advs_cs_datefilter.js';
var fnameValue = Request.parameters.custparam_first_name;
if(fnameValue){
firstname.defaultValue =fnameValue;
var fnamecustomerSearch = search.create({
type:'customrecord_advs_customer_entry_form',
filters:['custrecord_advs_first_name',"startswith",fnameValue],
columns:[
search.createColumn({name: "name"}),
search.createColumn({name: "custrecord_advs_first_name"}),
search.createColumn({name: "custrecord_advs_last_name"}),
search.createColumn({name: "custrecord_advs_email"}),
search.createColumn({name: "custrecord_advs_phone"}),
search.createColumn({name: "internalid"}),
search.createColumn({name: "id"}),
search.createColumn({name:"created"})
]
});
var counter = 0;
fnamecustomerSearch.run().each(function(result) {
log.debug("my result", +result);
var oldfullname = result.getValue('name');
var InternalidVal = result.getValue('internalid');
var firstname=result.getValue('custrecord_advs_first_name');
var lastname=result.getValue('custrecord_advs_last_name');
var email=result.getValue('custrecord_advs_email');
var phone=result.getValue('custrecord_advs_phone');
var recordid=result.id;
mysublist.setSublistValue({
id: 'custpage_advs_sublist_internalid',
line: counter,
value: InternalidVal
});
mysublist.setSublistValue({
id: 'custpage_advs_sublist_fullname',
line: counter,
value:oldfullname //....and so on and whatever I'm getting on the search
}); // I'm setting those on sublist values on the line
return true;
});
}
else if(((startDateValue)&&(endDateValue)) &&((endDateValue>startDateValue))){
startdate.defaultValue =startDateValue;
enddate.defaultValue=endDateValue;
var datecustomerSearch = search.create({
type:'customrecord_advs_customer_entry_form',
filters:[
["created","onorafter",startDateValue],
'or',
["created",'onorbefore',endDateValue],
],
columns:[
search.createColumn({name: "name"}),
search.createColumn({name: "custrecord_advs_first_name"}),
search.createColumn({name: "custrecord_advs_last_name"}),
search.createColumn({name: "custrecord_advs_email"}),
search.createColumn({name: "custrecord_advs_phone"}),
search.createColumn({name: "internalid"}),
search.createColumn({name: "id"}),
search.createColumn({name:"created"})
]
});
var counter = 0;
datecustomerSearch.run().each(function(result) {
log.debug("my result", +result);
var oldfullname = result.getValue('name');
var InternalidVal = result.getValue('internalid');
var firstname=result.getValue('custrecord_advs_first_name');
var lastname=result.getValue('custrecord_advs_last_name');
var email=result.getValue('custrecord_advs_email');
var phone=result.getValue('custrecord_advs_phone');
var recordid=result.id;
const view_url = url.resolveRecord({
recordType:'customrecord_advs_customer_entry_form',
recordId: recordid,
isEditMode: false
});
mysublist.setSublistValue({
id: 'custpage_advs_sublist_internalid',
line: counter,
value: InternalidVal
});
mysublist.setSublistValue({
id: 'custpage_advs_sublist_fullname',
line: counter,
value:oldfullname
});
mysublist.setSublistValue({
id: 'custpage_advs_sublist_fname',
line: counter,
value: firstname
}); // I'm doing the same what I did on last condition
counter++;
return true;
});
}
else // POST part just I'm creating record & setting the values and saving
{
var Fname= Request.parameters.custpage_advs_first_name;
var Lname=Request.parameters.custpage_advs_last_name;
var Email=Request.parameters.custpage_advs_email;
var Phone=Request.parameters.custpage_advs_phone;
var Fullname=Fname+' '+Lname;
var customRecord=record.create({
type:'customrecord_advs_customer_entry_form',
isDynamic:true,
});
customRecord.setValue({
fieldId:'name',
value:Fullname
});
redirect.toSuitelet({
scriptId: 'customscript_advs_ss_datefilter',
deploymentId: 'customdeploy_advs_ss_datefilter',
});
}
}
return{
onRequest:onRequest
}
});
here is my client script
here only I had a doubt on how to give condition
Actually, my need is If we select both dates on as per logically that means
let me tell scenario
#1:START DATE is 09/12/2022 and END DATE is 17/12/2022{//its like Start date is less than end date search should happen as well as it
has to set the values in the sublist }
#2 END DATE IS 17/12/2022 END DATE is 09/12/2022{ // it is like reverse process absolutely there will be no condition so what I
have to do is I need to give a pop up prevent user to select date
like this }
here is my client script and also I'm proving the screenshots of error page and design of my suitelet
define(['N/currentRecord','N/search','N/record','N/url','N/format'],function(currentRecord,search,record,url,format){
function fieldChanged(context) {
var recordObj=context.currentRecord;
// var name = context.fieldId;
var startDateValue=recordObj.getValue({
fieldId:'custpage_advs_start_date'
});
var endDateValue=recordObj.getValue({
fieldId:'custpage_advs_end_date'
});
if((startDateValue)&&(endDateValue)){
var startresponseDate=format.format({
value:startDateValue,
type:format.Type.DATE
});
var endresponseDate=format.format({
value:endDateValue,
type:format.Type.DATE
});
alert("The Customer entry Records that you have entered is between the dates " +startresponseDate +" and "+endresponseDate +" Click ok to continue " );
var suiteUrl = url.resolveScript({
scriptId: 'customscript_advs_ss_editviewcolumn',
deploymentId: 'customdeploy_advs_ss_editviewcolumn',
returnExternalUrl:false,
params : {
custparam_start_date: startresponseDate,
custparam_end_date: endresponseDate //define a parameter and pass the value to it
}
});
}
else{
return true;
}
setWindowChanged(window,false);
window.location = suiteUrl;
}
return{
fieldChanged:fieldChanged
}
});
please someone help me to solve my issue
As far as the dates are concerned you probably want to get the timestamps by doing something like: var startresponseDateTs = startresponseDate.getTime(); and then once you have the numbers you can just compare those. In NS you may be able to literally compare the NS Dates just (date1 > date2) but I'm not 100% about that one.
*By the way any of these could be causing the unexpected error:
(1) Your suitelet is missing a bracket above the final return.
(2) all of the "mysublist"'s seem to be undefined. The sublist needs to be created just like you created the form: var mysublist = form.addSublist({ id: 'custpage_a_sublist_id', type: serverWidget.SublistType.LIST, label: 'Hello Sublist' });
ps. adding a try {} catch(err){} block into the code could help. Not always. If its still not working you're about to get a masterclass in using the debugger :P
You need to call the client script before/ above the response of suitelet.
and try to add alert after a block of code if you don't know how to use debugger for each variable as a testing of client script execution.
like:-
alert(" startDateValue "+startDateValue);
alert(" endresponseDate"+endresponseDate);
alert("line no 110"); //for line no to get exact line with error.
so that you find the line where you are actually getting the error.
Thanks

How to save date type dd/mm/yyyy format in mongodb

Tried to save date format like dd/mm/yyyy in mongodb but this is saved like 2020-06-01T18:30:00.000Z.I want to save like 2020-06-01 in mongodb.How to do it?
Here my code:
data.model.js:
const mongoose = require('mongoose');
var userSchemaData = new mongoose.Schema({
p_id: {
type: String
},
product_today: {
type: Date
},
product_afterfive: {
type: Date
}
}, {
versionKey: false,
collection: 'data'
});
module.exports = mongoose.model('Data', userSchemaData);
data.controller.js:
var moment = require('moment');
var todayDate = new Date();
var afterfiveDays = new Date(new Date().getTime() + (5 * 24 * 60 * 60 * 1000));
module.exports.insertData = (req, res, next) => {
let collectionName = req.query.collection;
var Product= mongoose.model(collectionName);
var todayDateFormat = moment(todayDate, 'DD-MM-YYYY').format('MM-DD-YYYY');
var afterfiveDaysFormat = moment(afterfiveDays, 'DD-MM-YYYY').format('MM-DD-YYYY');
var product = new Product({
p_id: "CS1",
product_today:todayDateFormat,
product_afterfive: afterfiveDaysFormat
});
product.save(function(error, document) {
if (error) { console.log(error); } else {
console.log("Successful inserted");
res.json({ success: true, msg: 'User inserted.', cname: collectionName });
}
});
As stated in the documentation, mongoose will create a native Date object from the provided date value (see https://mongoosejs.com/docs/tutorials/dates.html)
The reason for this is probably that MongoDB's underlying type for "date" is
BSON Date is a 64-bit integer that represents the number of
milliseconds since the Unix epoch (Jan 1, 1970). This results in a
representable date range of about 290 million years into the past and
future.
so there's no date-type without the time. You can make sure in your application-code to insert dates with the time set to 00:00:00 or store the the "YYYY-MM-DD"-value as a String instead of a Date.

FabricJs: Limit grouping to only 1 level deep - Ungroup all objects before grouping

I do not want the user to be able to group a grouped item within another group. My solution to achieve this is basically when the user clicks on the 'Group' button, I am ungrouping everything and then grouping the selection again.
My problem is that when this happens, the items that are ungrouped, become duplicates. One set on the canvas, and one set within the new group.
Here is a video of what I mean...
https://screencast-o-matic.com/watch/cbXQfa2lJg
Here is my code...
export function groupSelectedItems() {
canvas = document.getElementById("c").fabric;
var activegroup = canvas.getActiveGroup();
var objectsInGroup = activegroup.getObjects();
//Ungroup all items first. This will limit grouping to only one level deep.
objectsInGroup.forEach(function(o) {
if(o.type=="group"){
//ungroup items within this group
var items = o.getObjects();
o.destroy();
canvas.remove(o);
items.forEach(function(i) {
canvas.add(i);
activegroup.addWithUpdate(i)
canvas.renderAll();
});
}
});
//Create the group
activegroup.clone(function(newgroup) {
canvas.discardActiveGroup();
objectsInGroup.forEach(function(object) {
canvas.remove(object);
});
canvas.add(newgroup);
newgroup.setControlsVisibility({'tl': false, 'tr': false, 'bl': false, 'br': false, 'ml': false, 'mr': false, 'mb': false, 'mt': false});
}, ['id', 'componentType', 'shape']);
canvas.renderAll();
}
function groupSelectedItems() {
canvas = document.getElementById("c").fabric;
var activegroup = canvas.getActiveGroup();
activegroup.clone(function(newgroup) {
canvas.discardActiveGroup();
activegroup.forEachObject(function(object) {
canvas.remove(object);
});
newgroup.forEachObject(function(object) {
if (object.type == 'group') {
object.destroy();
newgroup.removeWithUpdate(object);
object.forEachObject(function(obj) {
newgroup.addWithUpdate(obj);
})
}
});
canvas.add(newgroup);
}, ['id', 'componentType', 'shape']);
}
Check all the object in group, if any group object is present then ungroup all the object and then add to canvas.

How to handle song removal event in jPlayer with jPlayerPlaylist add-on

This is my code:
var myPlaylist = new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [
{
title:"Right Now(Na Na Na)",
artist:"akon",
mp3: "http://7xiaao.com1.z0.glb.clouddn.com/Akon - Right Now(Na Na Na).mp3"
//oga: "/music/",
//poster: "images/m0.jpg"
}
], {
playlistOptions: {
enableRemoveControls: true,
autoPlay: false
},
swfPath: "/res/plugin/jPlayer/dist/jplayer",
supplied: "mp3",
smoothPlayBar: true,
useStateClassSkin: true,
keyEnabled: true,
audioFullScreen: false,
});
jPlayerPlaylist add-on doesn't seem to provide a way to handle song removal event.
The workaround is to handle click events on x yourself, for example:
$('.jp-playlist').on('click', '.jp-playlist-item-remove', function(){
// Determine song index if necessary
var index = $(this).parents('li').index('.jp-playlist li');
// Retrieve song information, if necessary
var song = myPlaylist.playlist[index];
});

Can't find records in Waterline by date/time

how compare a datetime in sails.js Model? here it is what i did but without luck.
var _date = moment().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z';
Game.find({
where:{
active: true,
start: {
'>=' : _date
}
},
limit: 1,
sort: 'start asc'
}, function(err, game) {
console.log('ERROR: ' + err);
console.log('Game OBJ' + game.toString());
});
The datetime type is transformed into an actual Javascript date in Waterline (the Sails ORM). So it needs to be compared against a date object, not a string. You can keep your code exactly as it is, but change the first line to:
var _date = new Date(moment().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z');
Then your query should find all Games that start in the future.
Of course since your code is just returning current date, you don't really need moment at all:
var _date = new Date();
will work just as well.
var _date = moment().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z';
you need to convert above string variable to date variable using below line
var tempDate = new Date(_date);
Now use $gte instead of '>='
Game.find({
where:{
active: true,
start: {
$gte : tempDate
}
},
limit: 1,
sort: 'start asc'
}, function(err, game) {
console.log('ERROR: ' + err);
console.log('Game OBJ' + game.toString());
});
You can also use $gt, $lt, $lte.

Resources