I should preface this post by saying that I am a very elementary developer with a generic IS degree. Without going into too much detail, I was given a moderately large web application from an interning software engineer to support an enhance if need be. It was written primarily in Python, JavaScript and HTML5 and utilizes a Google Map API to visually represent the location and uses of given inputs. This leads me to my question.
There is a date picker modal that the application/user utilizes. They pick a START and END date, in the default format YYYY-MM-DD (if the user does not use that exact format (i.e. 2015-09-29) the date picker will not work), and the application then goes to the DB and picks the given inputs between those dates and represents them on the map. I have been told that, for usability, I have to make the program accept multiple date formats (i.e. September 29 2015, 09-29-2015, 9-29-2015, 9/29/2015). How would I go about doing this?
You can use Javascript to give the user the feedback that the correct format(s) is being used. But if you are taking any data to your server be sure verify the data on the server.
To verify the correct dataformat you can use Regular expressions and check if any format is correct. You should iterate through all allowed possibilities until one is found correct.
Your best bet from the user-experience standpoint is not to try and parse multiple formats but to normalize the input being accepted.
For dates, wouldn't you rather use a calendar picker instead of manually typing in the dates?
Have a look at this jQuery solution, or you can Google, there are plenty that don't use jQuery, and you can usuaslly specify the outupt format so you get the format you require.
Here's an example doing what you want: http://jsfiddle.net/ezygkgxt/
HTML
<label>Date: <input name='date' /></label>
<input type='hidden' id='actualDate' />
JS
$("input[name='date']").datepicker({
altFormat: "yy-mm-dd",
altField: "#actualDate"
});
$("input[name='date']").change(function(){
window.alert("The current chosen date is: "+$("#actualDate").val());
});
Related
I am currently working on a web application and I try to make the website multilingual.
From The user I got the following things:
language - from $_SERVER['HTTP_ACCEPT_LANGUAGE']
country - from the useres IP address (with an API)
Now, the website takes the language and shows the page in the correct language - for example english or german. Now I want to format numbers and dates and I dont know what should I use to format a date for example:
Germany: dd.MM.yyyy
United States: MM/dd/yyyy
But what should I use to format the date? The language or the country?
What if a user is in the US but speaks german? Should I use the US or the german format?
Would be nice to hear your opinion about that and how you handle localization.
The questions you are asking are solved using Locales. A locale is specific to a language, and then possibly more specific with geographical information and script variants.
CLDR is a repository of information relating to locales. You can find the names of specific cities in any languages, for example, or see how they format dates in a specific area.
You can leverage this data in conjunction with the Globalize.js library and its date formatting module.
See this answer for a general overview of how to use Globalize.js.
Is there a simple, established way to allow free-form date entry on a web page and parse the input text to get a Date value? We have a new requirement to go from using a date picker to allowing free-form date entry. So the user could theoretically enter any of the following:
12/7/41
12-7-1941
Dec 7, 1941
And we would have to attempt to parse it and make a date out of it.
I have attempted to find something online but the closest is this JQuery widget which doesn't do the free-form thing. There's also DateJS but it looks unfinished and development stopped in 2008. I'm just wondering if there's anything else out there.
MomentJS has what you are looking for. It's a robust library with almost all your time and/or date needs handled.
MomentJS Parsing: http://momentjs.com/docs/#/parsing/
I have 3 date and time fields (its date only).
But I want to limit the user not to be able to select future date.
I mean dates after today's couldn't be selected in the date picker.
How can I do it?
Crm datetime field doesn't support this type of functionality. You'll need to create your own html webresource and use a well-known library / control such as jquery datepicker.
Once you have the resource in place syncing the picker value with the hidden datetime value should be relatively easy using the form onload and onsave events.
You have to write a validator, either in plugin or JavaScript (or business rules), or perhaps both.
JS only works in the forms but has the possibility to give a prettier error message, with the business rules you can have a valitation which gives messages inline. If you only add data using the GUI, it might be enough to just use JS/business rules but if data can come any other way I would secure it with a plugin as well.
The validator is pretty simple, retrieve the field and compare it with a date object today. It could be a bit worse if there are a lot of timezones involved, we don't like timezones....
I have seen and read a number of comments regarding calculating the days between dates, as it relates to JS. My question is-I need to calculate this information in Adobe LiveCycle Designer. I have the two fields I need to reference in the script. The first is the static field with the last known date of an event, the second is the current date/time (which is entered by the end user). I need to know how to write the script to find the difference between these two fields, with the calculation resulting in days. I do not need to be exact, daylight savings time, leap year, time zones etc. are not important. Just need to get to an integer. Thanks in advance for the help.
The quick and dirty way to do it involves an epoch subtraction. In Javascript, the date epoch is available from Date.getTime(); as seen on W3 Schools. If you're looking for a more robust approach and if you have a need for additional date and time operation, I would suggest looking into Moment.js. Moment.js is technically a JavaScript library aimed at browsers, etc. but it can be wrapped in a Script Object to be used in an XFA form.
I'm looking for a way to have a textbox that allows users to type in a date in any format and turns around and formats that date in a 'mm/dd/yyyy' format. So the user could type in "Today" and it would turn the date as 02/24/2009 or they could type in Wednesday Feb 24 and formatting would automatically pick up. Remember the Milk does this (but I believe server side). This is asp.net so I could do via ajax web service call but I would prefer to do this via Javascript. I'm looking for a general technique or existing library to help with this.
Check out http://www.datejs.com/