/*
 * Author       : zchelp
 * Generated on : 22-Nov-2009 22:28:34
 * Version      : 3.0
 */
application "TwoFieldsInOne"
{
    type = public
    date format = "dd-MMM-yyyy"
    time zone = "America/Los_Angeles"
    section Home
    {
        form  FormA
        {
            
            Course
            (
                type  =  picklist
                values  =  {"Others",   "Chemistry",   "Mathematics",   "English"}
                sortorder  =  ascending
                on user input
                {
                    if (input.Course  ==  "Others")
                    {
                        show OtherCourse;
                    }
                    else
                    {
                        hide OtherCourse;
                    }
                }
            )

            OtherCourse
            (
                type  =  text
            )

            actions
            {
                on add
                {
                    on load
                    {
                        hide OtherCourse;
                        if (count(FormB)  !=  0)
                        {
                            for each dat1 in FormB  [ID != 0]
                            {
                                Course:ui.add(dat1.Courses);
                            }
                        }
                        for each dat2 in FormA  [ID != 0]
                        {
                            if (dat2.OtherCourse  !=  "")
                            {
                                Course:ui.add(dat2.OtherCourse);
                            }
                        }
                        Course:ui.add("Others");
                    }
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                        on validate
                        {
                            if ((count(FormA[OtherCourse == input.OtherCourse])  >  0)  &&  (input.OtherCourse  !=  ""))
                            {
                                alert "Please select the course form the Course dropdown";
                                cancel submit;
                            }
                        }
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  FormA_View
        {
            displayname = "FormA View"
            show  all  rows  from  FormA 
            (
                Course
                OtherCourse
            )
            filters 
            (
                Course
            )
            options
            (
                display rows = 100
            )
        }

        form  FormB
        {
            
            Courses
            (
                type  =  text
            )

            actions
            {
                on add
                {
                    Submit
                    (
                        type  =  submit
                        displayname  =  "Submit"
                    )
                    Reset
                    (
                        type  =  reset
                        displayname  =  "Reset"
                    )
                }
                on edit
                {
                    Update
                    (
                        type  =  submit
                        displayname  =  "Update"
                    )
                    Cancel
                    (
                        type  =  cancel
                        displayname  =  "Cancel"
                    )
                }
            }
        }

        list  FormB_View
        {
            displayname = "FormB View"
            show  all  rows  from  FormB 
            (
                Courses
            )
            options
            (
                display rows = 100
            )
        }

    }

}
