Date Range - auto populate "to" date with "from" date
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
Date Range - auto populate "to" date with "from" date
I have a screen with 2 date fields - "from" and "to" date range. If the user selects a "from" date using the calendar widget, I would like it to automatically populate the "to" date field so that both values are the same. I would also like the calendar widget for the "to" date field to display the selected month from the "from" date field so the user remains in the desired month in the event they want to change the day.
example:
User selects October 15th from calendar widget, "from" date = 10/15/2014 and "to" date = 10/15/14 AND if user clicks on "to" date to change the day, calendar widget starts with October.
Is this possible? Thank you......
example:
User selects October 15th from calendar widget, "from" date = 10/15/2014 and "to" date = 10/15/14 AND if user clicks on "to" date to change the day, calendar widget starts with October.
Is this possible? Thank you......
-
- Experienced User
- Posts: 122
- Joined: Tue May 22, 2012 6:45 am
- First Name: Dieter
- Last Name: Schröder
- Company Name: Ecclesia Holding GmbH
- State / Province: Outside Canada/USA
- Country: Germany
- Contact:
Re: Date Range - auto populate "to" date with "from" date
You can code an OnChange-Event for the first datefield:
changeElementValue("Date2", getElementValue("Date1"));
For your second problem (adjusting the month) i have no idea.
Dieter
changeElementValue("Date2", getElementValue("Date1"));
For your second problem (adjusting the month) i have no idea.
Dieter
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
Re: Date Range - auto populate "to" date with "from" date
Thanks Dieter, but it did not work for me??? Thoughts?
- Attachments
-
- Capture.PNG (7.93 KiB) Viewed 2522 times
-
- Capture2.PNG (6.5 KiB) Viewed 2522 times
-
- Profound User
- Posts: 76
- Joined: Fri Jan 11, 2013 6:11 pm
- First Name: Sean
- Last Name: Tyree
- Company Name: US HealthWorks
- State / Province: California
- Zip / Postal Code: 91355
- Country: United States
- Contact:
Re: Date Range - auto populate "to" date with "from" date
Try this code for your onchange event:
pui.set("emenddate", get("emstartdate"));
I noticed that your start date element might be misspelled: "emstardate"?
Sean
pui.set("emenddate", get("emstartdate"));
I noticed that your start date element might be misspelled: "emstardate"?
Sean
-
- New User
- Posts: 3
- Joined: Fri Sep 26, 2014 12:24 pm
- First Name: Dieter
- Last Name: Schröder
- Company Name: Ecclesia Holding GmbH
- State / Province: Outside Canada/USA
- Country: Germany
- Contact:
Re: Date Range - auto populate "to" date with "from" date
I am at home. In Germany it is weekend now. So i had to login with a new account.
Are you sure that you really used the ID of your widgets? Or did you use the name of the bound RPG variables? The ID of a widget is shown in the Visual Designer. When you click on a widget you can see the id as the first property of the widget. In Javascript you allways have to use the id instead of the rpg variable.
Maybe this helps.
Dieter
Are you sure that you really used the ID of your widgets? Or did you use the name of the bound RPG variables? The ID of a widget is shown in the Visual Designer. When you click on a widget you can see the id as the first property of the widget. In Javascript you allways have to use the id instead of the rpg variable.
Maybe this helps.
Dieter
-
- New User
- Posts: 3
- Joined: Fri Sep 26, 2014 12:24 pm
- First Name: Dieter
- Last Name: Schröder
- Company Name: Ecclesia Holding GmbH
- State / Province: Outside Canada/USA
- Country: Germany
- Contact:
Re: Date Range - auto populate "to" date with "from" date
Another tip: I think the name of the ids have to be case sensitive.
Dieter
Dieter
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Date Range - auto populate "to" date with "from" date
I agree with Dieter. Make sure you are using the ids of the fields, not the name of the bound variables. And, yes, ids are case-sensitive, so make sure you match the upper/lowercase exactly.
Sean, fwiw, pui.set() and changeElementValue() are aliases for teh same routine, it does not matter which one you use. The difference between getElementValue() and get() is that get() will trim blanks from the result, and getElementValue() will not... they are otherwise identical.
Sean, fwiw, pui.set() and changeElementValue() are aliases for teh same routine, it does not matter which one you use. The difference between getElementValue() and get() is that get() will trim blanks from the result, and getElementValue() will not... they are otherwise identical.
-
- Experienced User
- Posts: 147
- Joined: Tue Jun 17, 2014 4:00 pm
- First Name: Patti
- Last Name: Bednarz
- Company Name: McGard
- State / Province: New York
- Country: United States
- Contact:
Re: Date Range - auto populate "to" date with "from" date
Yes, spelling was correct (I had to abbreviate). I actually tried the statement both ways.. with the id and the bound name. Neither worked.
Sean, I just tried what you suggested using the id and it did not work. The "OnChange" does not seem to be registering. (I was having a similar issue with an auto-fill drop-down and when I moved the code to "OnSelect" it worked. )
This is what it looks like now:
Sean, I just tried what you suggested using the id and it did not work. The "OnChange" does not seem to be registering. (I was having a similar issue with an auto-fill drop-down and when I moved the code to "OnSelect" it worked. )
This is what it looks like now:
- Attachments
-
- Capture3.PNG (9.74 KiB) Viewed 2511 times
-
- Capture2.PNG (10.35 KiB) Viewed 2511 times
-
- Capture.PNG (8.93 KiB) Viewed 2511 times
-
- New User
- Posts: 3
- Joined: Fri Sep 26, 2014 12:24 pm
- First Name: Dieter
- Last Name: Schröder
- Company Name: Ecclesia Holding GmbH
- State / Province: Outside Canada/USA
- Country: Germany
- Contact:
Re: Date Range - auto populate "to" date with "from" date
Today afternoon i tried my posted code and it worked. I am on version 4.8.6.
Please try the following (so did i):
Open the designer and create a pure new mask.
Draw two date widgets onto the screen. In my case the widgets automatically got the ids "Date1" and "Date2".
Then put my posted code in the OnChange element of Date1:
changeElementValue("Date2", getElementValue("Date1"));
Then give the screen format a name (i gave it the name "x").
Then launch the preview.
In my case it worked.
If this works in preview you may have a problem in your browser or in the other JavaScript code of your mask.
Please let me know your result.
Dieter
Please try the following (so did i):
Open the designer and create a pure new mask.
Draw two date widgets onto the screen. In my case the widgets automatically got the ids "Date1" and "Date2".
Then put my posted code in the OnChange element of Date1:
changeElementValue("Date2", getElementValue("Date1"));
Then give the screen format a name (i gave it the name "x").
Then launch the preview.
In my case it worked.
If this works in preview you may have a problem in your browser or in the other JavaScript code of your mask.
Please let me know your result.
Dieter
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Date Range - auto populate "to" date with "from" date
Patti, the onchange will only fire when the value of the field has changed. Maybe something like 'onblur' would be a better choice? this will fire every time you leave the field.
An easy way to tell if the event is firing is to stick an alert() into the code. So in your onchange example, you might set onchange to: alert("fired"); pui.set("EndDateInput", get("StartDateInput"));
A popup box will appear each time the event fires, and that will make it clear that the code is running. (Obviously, you will want to remove the alert when you're done testing.)
An easy way to tell if the event is firing is to stick an alert() into the code. So in your onchange example, you might set onchange to: alert("fired"); pui.set("EndDateInput", get("StartDateInput"));
A popup box will appear each time the event fires, and that will make it clear that the code is running. (Obviously, you will want to remove the alert when you're done testing.)
Who is online
Users browsing this forum: No registered users and 1 guest