Form Actions - On Load
Description
The on load form action script is used to dynamically alter a
form when it is loaded. The form actions are executed when the form is
loaded by a user to add a new record or when the form is loaded
by a user to edit an existing record. For example, to set a date
field in the form with the current date or to hide a field when the form
is loaded.The script itself runs on the server side, immediately after
the user's request is sent to the user's browser.
Syntax
On Add: The on load script written in the actions
-> on add block is invoked when the form is loaded to add a new
record.
actions
{
on add { on load {
......................... } }
}
|
On Edit: The on load action script written in the actions
-> on edit block is invoked when the form is loaded to edit an
existing record.
actions
{
on edit { on load {
.................. } }
}
|
Examples
Some common scenarios when the on load script is used, is given below:
1. Display current date in the date
field when form is loaded - on add
You can create a date field and set it with the current date, using
the zoho.currentdate function inside on load script. The
following script will set the date field with the current date whenever
the form is loaded.
form SampleForm1
{
Date1
(
type = date
)
actions { on add { on load { Date1 = zoho.currentdate; } Submit ( type = submit displayname = "Submit" ) Reset ( type = reset displayname = "Reset" ) } on edit { Update ( type = submit displayname = "Update" ) Cancel ( type = cancel displayname = "Cancel" ) } }
}
|
2. Hide fields while loading a form on
edit
The on load action script in the following example, will be executed
when the user edits an existing record. The script will hide the fields
Name and EmailId in the form, and allow only the
other field values to be edited by the applicant.
form ApplicationForm
{
Name
(
type = text
)
EmailId
(
type = email
)
DateOfBirth
(
displayname = "Date Of Birth"
type = date
)
EducationalQualification
(
displayname = "Qualification"
type = picklist
values = {"Graduate", "PostGraduate", "Diploma", "Other"}
)
Experience
(
type = text
)
actions { on add { Submit ( type = submit displayname = "Submit" ) Reset ( type = reset displayname = "Reset" ) } on edit {
on load
{
hide Name;
hide EmailId;
} Update ( type = submit displayname = "Update" ) Cancel ( type = cancel displayname = "Cancel" ) } }
}
|
3. Set default value for fields on
add
You can set default value for fields including picklist while loading
a form. The following script will set the value "Available"
to the form field "Status".
actions
{
on add
{
on load
{ input.Status = "Available"; }
}
}
|
|