Calendar Month View

I could use a little guidance. I am using calendar month view to display daily data from a SQL query. When the user presses the forward or backward arrows I created, the query populates the calendar with data for that month. When they select a particular day the data for that day is displayed below the calendar for editing. When they press ‘enter’ the data is written back to the database via a SQL update command. It then appears on the calendar within 2 seconds as the query refreshes every 2 seconds.

The problem occurs when the user selects those few days from the previous month or the coming month that make up the first and last week of a month… The selected day then tries to populate my editing field with nonexistent data. How do I keep the selected day within the displayed month?

I’ll have a go at helping…
How about a dynamic property (integer) on the calendar called “selectedMonth” - an expression - set as:
dateExtract(toDate({Root Container.Month View.selectedDay}), “month”)+1
This provides the selected days month as an integer.
Then on the mouse click property of the calendar I used:

if event.source.selectedMonth == event.source.month: print "yes" else: print "no"

If the selected day is the same month as the calender it prints YES, if not it prints NO, obviously your code would decide whether to populate the date fields or not???
Might be a solution :scratch:

Or how about a dynamic property, string, "selected_day"as well as the original “selectedMonth”
mouse click for month view:

event.source.selected_day=event.source.selectedDay

mouse released for monthview

if event.source.selectedMonth != event.source.month: event.source.selectedDay = event.source.selected_day

This keeps the selected date as it was if the clicked date is not in the displayed month. I think this is perhaps what you were after. You would need to populate the data fields on mouse released as the selected date momentarily becomes “outside” the month until the mouse is released.

Thank you Brett. Your suggestion worked for me with the following modification:

I bound the following to selected_Day:
if (({Root Container.Month View.month} = {Root Container.Month View.selectedMonth}),
{Root Container.Month View.selectedDay},{Root Container.Month View.selected_Day})

and set the Event Handler for the calendar to ‘property change’:
if event.source.month != event.source.selectedMonth:
event.source.selectedDay = event.source.selected_day

I chose to use ‘property change’ instead of ‘mouse click’ as I read somewhere in the forum that ‘property change’ is the trigger for selectedDay

Without the condition as part of the ‘selected_Day’ binding, if a user pressed a date outside the month, the first time everything would be okay. However, on a second consecutive press outside the month the newly captured selected_Day would cause a date outside the month to be captured.

I need to learn to use Dynamic Properties more often.

Actually, after testing this further, the logic keeps me from selecting a date outside the month. But the date it pulls as an alternative via the binding to selected_Day doesn’t seem to be working right. :frowning:

weertske,
Completely agree on your correction

[quote]I bound the following to selected_Day:
if (({Root Container.Month View.month} = {Root Container.Month View.selectedMonth}),
{Root Container.Month View.selectedDay},{Root Container.Month View.selected_Day})
[/quote]
But if you can explain the problem regarding the date someone may be able to help.
I put both selected_day (dynamic property) and Selected Day (calendar property) on screen as a label through expressions like:
toDate({Root Container.Month View.selectedDay})
both return nice looking date formats i.e.:
2011-12-14 00:00:00
but only selected_day works correctly, the calendars Selected Day still picks up the out of range date even though the property strip in the designer appears to show both working correctly.
I’m guessing if you used the standard Selected Day and not the dynamic property it would not work.

I also found if you changed month the selectedMonth expression errored so I put this in to return the calendar month until a date is clicked on:

try(dateExtract(toDate({Root Container.Month View.selectedDay}), "month")+1, {Root Container.Month View.month})

Hope I’m not leading you down the wrong path with this :scratch:

I think I came up with a better way of doing this:
Create two dynamic properties:

selectedMonth, integer
Ready, Boolean

Create the following event handler for property change on the calendar:

[b]date1 = event.source.selectedDay
yr1,event.source.selectedMonth,day1 = date1.split(’-’)

if event.source.selectedMonth == event.source.month:
event.source.Ready = 1
else:
event.source.Ready = 0[/b]

Now, the Ready boolean and whatever other logic I have will work right all the time. The problem before was that when selectedMonth was evaluated as part of a property binding, it would sometimes get evaluated after an unacceptable date was selected - leading to sporadic errors. By evaluating selectedMonth as part of the event handler, I can ensure that it always gets evaluated before the rest of the logic commences.