I'm trying to populate a form on a site with values passed through GET. The two fields I'm having trouble with are input tags that are of type type="date" or type="time". Chrome has this nice feature that gives you a drop down calendar to select a date:
Chrome also does something similar for the Time field. The problem is that it doesn't like javascript that tries to populate those types of form fields. I pass GET information like so:
The reason the date is formatted like this is because that's what the back-end requires (not what I'm working on) and the date comes directly from the back end code.
I have a function that auto-populates document.$_GET as an array with all passed values from GET. I also have date.js included, which allows me to use the Date.parse functionality and some other stuff. I pass it through javascript like this:
if(document.$_GET['time']!=undefined)
document.getElementById('time').value=document.$_GET['time'];
if(document.$_GET['date']!=undefined){
var date = new Date();
date = Date.parse(document.$_GET['date']);
alert(date.toString('MM-dd-yyyy')); // <-- Debugging
document.getElementById('date').value = date.toString('MM-dd-yyyy'); //WHY WON'T YOU WORK!?
}
On Safari I get what I expect to get:
With Chrome I'm left with empty form fields:
I'm stumped and not sure how to remedy this. I need Chrome to autofill similar to how Safari does.
Google Chrome is strict about the format of the Date.
The date works with the following format, YYYY-MM-DD.
The time works with military time. (24h clock)
Here's a sample,
http://jsfiddle.net/vFnxw/2/
$("#date").attr({
value:"2012-09-28"
})
$("#time").attr({
value:"23:59:59"
})
Here are the sources
http://dev.w3.org/html5/markup/input.date.html
http://dev.w3.org/html5/markup/input.time.html
Related
EDIT: My def form_invalid of the `class ProviderUpdateView(UpdateView):
def form_invalid(self, form):
print("form is invalid")
print(form.errors)
return HttpResponse("form is invalid.. this is just an HttpResponse object")
I might open a second question to figure out why this isn't rendering on the form and yet some 'must fill out this field is' might have to do with crispy forms not sure I didn't write this part and have to look into it :/
I have a date field that comes across in the data field of an ajax call. I can get the data just fine in my views.py
dateJ = request.GET.get('date_joined_group')
This is great, but when I try to throw it into my model it dies everytime. I need to 'clean' the data, I know my forms when I am just doing standard get post ops works and does this automagically. Is there a way I can invoke this automagic when not using form stuff but using the ajax call?
I tried this:
dateObj = datetime.datetime.strptime(str(dateJ), '%m-%d-%Y')
Then in my model:
grpProvInfo.date_joined_group = dateObj
grpProvInfo.save()
This worked, till I used the date picker on the form which put it in as 4/29/2009
So the slashes broke my 'slick fix', gotta be an easier way then trying to account for all the possibilities just not sure how to invoke it from a little def method I have for the ajax call in my python.
So there are a few different python libraries that can help you in a big way. This one, dateparser, lets you input as many different formats as you'd like to be able to parse, and returns a datetime object. This would solve your problem with slashes. Another piece of advice would be to always serve your date in the same format regardless of how it is input. If you use django forms and the date field, you will automatically get validation (of a valid date string), and that combined with dateparser should allow you to safely parse any date string.
And for simplicity's sake, you should be able to change the default format of the datepicker. But that's not truly the answer for how to fix your problem
date Field image
unable to set date info past specified date field using sendKeys function
Have tried using java script but could not set the value.
update
HTML
driver.findelementBy("//label[text()='Past Specified']/../div[#class='radioHide']//input[1]").sendkeys("01082016");
and
(JavascriptExecutor)driver.executeScript(arguments[0].setAttribute('value', '"+sText+"');",element))
please help
You date format is incorrect. Try the following,
driver.findelementBy("//label[text()='Past Specified']/../div[#class='radioHide']//input[1]").sendkeys("01/08/2016");
or using javascript
String sText="01/08/2016";
(JavascriptExecutor)driver.executeScript(arguments[0].setAttribute('value', '"+sText+"');",element))
I'm using AngularJS to for user to choose week from a input week tag, but there is something bizarre qbout the format.
I've read that the format should be yyyy-W##, and I do this already, but angularJS still gives me this error:
Error: [ngModel:datefmt] Expected `2015-W51` to be a date
http://errors.angularjs.org/1.4.8/ngModel/datefmt?p0=2015-W51
and this is my tag:
<input type="week" ng-if="header.type==='week'" ng-model="entry[header.className]" ng-change="vos.fieldSelectionChanged(field_id,entry.record_id)"/>
So as you see, the input type is week, here, I'm using this tag inside of a ng-repeat, so I'm loading the data from the entry[] array, and the week loaded is 2015-W51.
So please tell me what I'm doing wrong , is there a best practice using this tag with AngularJS?
Thanks !
Edit 1 - more code
I've found this:
http://codepen.io/empirefox/pen/MYyoao
It demonstrates how to use input week with a date, but the problem is that I don't have the data as dates.
And at the right part of the page, you have this :
$scope.value = new Date(2013, 0, 3);
Change it to this :
$scope.value = "2015-W20";
And it gives me the same error. So if we can solve this one, I think we can also solve the problem on my page.
Angular uses native Date object to handle all its datetime-related inputs, but unfortunately Date instances does not have any methods to handle week numbers. It would be the best solution to stick with moment.js.
Coercion from string to ng-model-enabled value (in controller etc.):
$scope.value = moment("2015-W20").toDate();
Coercion from ng-model-enabled value to string (in form submit handler etc.):
moment($scope.value).format("YYYY-[W]WW"); // returns "2015-W20"
I am working on a parse (Facebook) app. I have a table however I want to be able to get the expired events (aka events that occur after some date). What is the best way to do this. I didn't see a date documentation with Parse.
My thought from dynamo experience was to simply save it and compare the values but this is costly. Is there a more efficient way?
Any ideas / anyone done this?
Thanks!
Just use the greaterThan, greaterThanOrEqualTo, lessThan and lessThanOrEqualTo methods on Parse.Query, and pass in date objects.
I.e.
var query = new Parse.Query("Event");
query.lessThan("eventDate", new Date());
This query will get you all objects from the table "Event", whose column "eventDate" (a Date column) contains a date that is before the current date.
I'm trying to convert an HTML table to Excel in Javascript using new ActiveXObject("Excel.application"). Bascially I loop through table cells and insert the value to the corresponding cell in excel:
//for each table cell
oSheet.Cells(x,y).value = cell.innerText;
The problem is that when the cell is in date format of 'dd-mm-yyyy' (e.g. 10-09-2008), excel would read as 'mm-dd-yyyy' (i.e. 09 Oct 2008). I tried to specify NumberFormat like:
oSheet.Cells(x,y).NumberFormat = 'dd-mm-yyyy';
But, it has no effect. It seems that this only affect how excel display the value, not parse. My only solution now is to swap the date like:
var txt = cell.innerText;
if(/^(\d\d)-(\d\d)-\d\d\d\d$/.test(txt)) txt = txt.replace(/^(\d\d)-(\d\d)/,'$2-$1');
But, I'm worrying that it is not generic and a differnt machine setting would fail this.
Is there a way to specific how excel parse the input value?
You can avoid Excel's date parsing by entering the data using its native 'serial' date format. e.g '22nd Dec 08' is 39804 as an Excel serial date. (See here for a good explanation of these)
Then format the cell as you did before.
determine what culture-neutral date formats excel supports
use javascript to parse your date string and output in the an appropriate format
I don't know what formats excel supports but you'd want something like .net's round trip or sortable formats, where it will always be read consistently.
for #2, if you can trust javascript to construct an appropriate date from whatever string you feed it that's fine. if you're not sure about that you might look at a library like datejs where you can be more specific about what you want to happen.
Instead of
oSheet.Cells(x,y).NumberFormat = 'dd-mm-yyyy';
set this:
oSheet.Cells(x,y).NumberFormat = 14;
In Vbscript, we use to resolve this by
If IsDate ( Cell.Value ) Then
Cell.Value = DateValue ( Cell.Value )
End If
Maybe, In java script also you need to play with same approach.
I've tried your code but at end of the process, I re-applied format to the columns containing dates. It works fine, no matter what local language you have configurated yor machine.
Being my excel object defined as 'template', as soon as I got it data filled, I applied (just for example):
template.ActiveSheet.Range("D10:F99").NumberFormat = "dd/MMM/yyyy;#";
best regards