Restrict previous dates in calendar

Restrict previous dates in calendar

Many time will come across scenarios where date picker should not allow user to select previous date (i.e. dates smaller than current date). But if will look at Smartform Date picker control, there is no property which allow us to stop user from selecting previous date.

But using Expression and Rules we can add functionality to restrict user from selecting previous date’s in date picker control.

Below is an example with 3 simple step, which provide this functionality in date picker control .

Step 1 : Add Controls to Layout

  • Drag and drop calendar control from controls menu available on Right Hand Side to layout page and add a datalabel  on top of this control to show message to user.disable dates in Date picker control Img1disable dates in Date picker control Img2
  • Now Select the calendar control which will show the Properties on right hand side, do the changes for Calendar control per your requirement. In my case I have Selected “Data Type “and “Picker Type” as Date, Date format to English (United Kingdom).

disable dates in Date picker control Img3

Step 2: Create Data Label Control to Add Expression

Drag and Drop Data Label to layout, select control to set its properties as below.
  • Uncheck visible property
  • Check Literal Property

disable dates in Date picker control Img4

  • Now click on ellipse Next to Expression property. This will show popup to “add/remove expression”.

disable dates in Date picker control Img5
Click on add and add expression as shown in below Image

disable dates in Date picker control Img6

Above used  expression is:

If(calStartDate >= CurrentDate)
   Then return “startDate”
Else
   return Empty Space
  • Save this and close Expression Popup. While closing expression, popup select none as Expression

Step 3 : Add Rule to Calendar control

  1. Add rule to check when Calendar value is changed then execute Expressiondisable dates in Date picker control Img7
  2. Then add if condition to check if calStartedDate contains EmptySpace.
  3.  If condition is true, then set Error message to Data Label and keep Visible value as true
  4.  Else keep message Text empty and visible value as false.disable dates in Date picker control Img8.jpg

Out Put:

disable dates in Date picker control Img9

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s