Tuesday, October 29, 2013

Specifying default values for form fields, using expressions

iFreeTools Creator, your easy web-based database software built for hosting on Google App Engine, now supports specifying default values for attributes in forms. The default values can be configured using the Default Value Expression in Attribute definition.


Expressions should return the result in the expected data-type. For details on using expressions, you may refer to our help docs.

Sample default value expression for each data type are given below:

Data Type

Examples

Single/Multi-line Text

  • "Velachery"
    Text values have to be provided within quotes.
  • val_from(user(), "Name")
    to set the currently logged-in user's name.
  • val_from(user(), "Email Id")
    to set the currently logged-in user's email-id.
Yes/No checkbox (Boolean)


  • True
  • False
  • val_from(user(),"Role") == "admin" to mark as Yes, if the current user has admin access.
Number Integer/Decimal numbers
  • 1
  • -2
  • 33.5
  • -44.75
  • val_from(fetch_one("Fee Details", "Year":year(), "Month":month()}), "Fees"))
    to fetch the values form an existing database record, in this case, from Fee Details entity, which matches the condition of having the Year attribute as the current year and the Month attribue as current month. From this matching record, we get the default-value from the Fees attribute.
Single line text - Choice Value

  • "Cash"
    Any of the choice values can be provided. For example, the above is valid if the choice values were : "Cheque", "Cash", "Bank Transfer"
Date
  • today()
  • today() + timedelta(5)
    to set the date value as 5 days from the current date.
Date and Time
  • now()
  • now() + timedelta(0,3600*10)
    to set the date-time value as 10 hours from the current date-time.
Image
  • key_id(val_from(fetch_one("Default Values",{}), "Default Profile Image"))
    to fetch the image form an existing database record, in this case, from Default Values entity, having an image-attribute with name as Default Profile Image.
Geographical Location (Geo Point)
  • "13.1207829,80.2377078" 
    in case you know the co-ordinates of a specific location, the value has to be provided within quotes.
  • val_from(fetch_one("Default Values",{}), "Default Location") 
    to fetch the location form an existing database record, in this case, from Default Values entity, having an geo-point-attribute with name as Default Location.
List (with string values)
  • ["English", "Spanish", "French"]
  • val_from(fetch_one("Default Values",{}), "Default Languages")
    to fetch the values from an existing database record, in this case, from Default Values entity, having an list-attribute with name as Default Languages.
Lookup field (Reference)
  • key_id(fetch_one("Teacher",{"Name":"John Smith"}))
    to fetch the values from an existing database record, in this case, from the Teacher entity, having Name as John Smith.

Hope you like our new feature. If you need assistance in using this feature or if you have suggestions, feel free to use the feedback form in our application.