Hi everyone,
I'm trying to automatically update a date field with Date.now() value using the Edit widget with some changes.
What ever I do, it does not update the field.
Can someone tell me what's wrong with my code?
this.editor = new Editor(params, this.editDiv);
this.editor.startup();
var feature;
var attInspector = this.editor.attributeInspector;
attInspector.showObjectID = false;
var theMap = this.editor.settings.map;
var saveButton = new dijit.form.Button({label:"שלח","class":"saveButton"});
dojo.place(saveButton.domNode, attInspector.deleteBtn.domNode, "before");
saveButton.on("click", function(evt) {
if (feature == null)
alert("Pleae enter values");
else {
if (feature.attributes["description"] == null) {
alert("Description field is required");
return;
}
feature.attributes["date1"] = Date.now();
theMap.infoWindow.hide();
}
});
attInspector.on("attribute-change", function(evt) {
feature = evt.feature;
feature.attributes["date1"] = Date.now();
feature.getLayer().applyEdits(null, [feature], null);
});
theMap.infoWindow.resize(350, 600);
this.resize();
},
Thanks a lot,
Miri
Miri,
Try this:
var currentDate = new Date(); var currentDate = Date.UTC(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate(), currentDate.getUTCHours(), currentDate.getUTCMinutes(), currentDate.getUTCSeconds(), 0); attInspector.on("attribute-change", function(evt) { feature = evt.feature; feature.attributes["date1"] = currentDate; feature.getLayer().applyEdits(null, [feature], null); });
Reference thread: Re: Hard-code Attribute Values for Fields with AttributeInspector?
Hi Robert,
Unfortunately it didn't help.
I think you ment to define two different variables, isn't it? something like:
var currentDate = new Date();
var currentDate1 = Date.UTC(currentDate.getUTCFullYear(), currentDate.getUTCMonth(), currentDate.getUTCDate(), currentDate.getUTCHours(), currentDate.getUTCMinutes(), currentDate.getUTCSeconds(), 0);
attInspector.on("attribute-change", function(evt) {
feature = evt.feature;
feature.attributes["date1"] = currentDate1;
feature.getLayer().applyEdits(null, [feature], null);
});
But anyway, both of them don't work.
I think it's more timimg Issue rather than the Date format. Only once, during Debug, I saw the date entered but I cannot reproduce it any more.
it's also related to the Editor or AttributeInspector classes in Javascript API rather than the Web AppBuilder.
Thanks a lot,
Miri