Forms

From nuBuilderPro
Jump to: navigation, search

Forms

The Browse Form

The Browse Form is a screen that displays multiple records from the same database table.

From the Browse Form it is possible to..

  • Search for a record
  • Add a new record
  • Print a list of records

Browse.png

The Edit Form

The Edit Form is a screen that displays one record for editing (and perhaps, related child records as below).

The Actions that can be performed from an Edit Form are.

  • Save
  • Add
  • Clone
  • Delete

Edit.png

The Creating an Edit Form

Creating an Edit Form is done actually using the built in System Edit Form within nuBuilderPro.

The properties of the built in Form's - Edit Form relate to Either the Browse Form or the Edit Form and are spread over a number of Tabs.

General Tab

Forms-General.png

Code

A unique Form name which can be used to directly reference this Form

Description

A short description of the purpose of this Form

Table

The database table this Form is using as a data base

Primary Key

The name of the Primary Key of this database table given in the table field.

Width

The width, in pixels, of the Edit form. (Defaults to 1000px when left blank)

Height

The height, in pixels, of the Edit form. (Defaults to 500px when left blank)

Breadcrumb Title

An SQL statement who's result can act as a descriptive title for this record as the last breadcrumb. This SQL can contain Hash Variables.

e.g.

SELECT 'Invoice No. #inv_number#'

As hash variables are only replaced, it is possible to place any text around it for a more descriptive breadcrumb title. SQL SQL code to retrieve data from a database and populate the browse Form.

e.g.

SELECT *
FROM invoice
INNER JOIN customer ON inv_customer_id = customer_id

Browse Tab

Forms-Browse.png

Form to Edit

The Edit Form that will be opened when a record on the Browse Form is selected. If this field is left blank, the current forms Edit Form will be used.

Row Pixel Height

Height of each of the Select-able Rows in the Browse Form.(if left blank this will default to 22px)

Rows Per Page

The number of rows that are visible on each Form (if left blank this will default to 25 rows)

(Browse height is calculate by Rows times by Row Height)

Browse Columns

Title

The title of this column, which will appear at the head of the column.

Display

The column of the database that is to be displayed in this column.

SQL formatting functions can be applied to the column as shown in Example 2.

Example 1.

cus_name

Example 2.

DATE_FORMAT(inv_date,'%m-%d-%Y')
Sort

The database column that this browse column is to be sorted on.

The direction of sorting is defined by the user clicking on the columns.

Example 1.

cus_name

Example 2.

DATE_FORMAT(inv_date,'%m-%d-%Y')
Align

How the text within the column are aligned. The choices are:

  • Left
  • Right
  • Center
Format

Format is for Date or Number values.

Formats that can be used ..

  • 10000
  • 10000.0
  • 10000.00
  • 10000.000
  • 10000.0000
  • 10000.00000
  • 13-Jan-2007
  • 13-01-2007
  • Jan-13-2007
  • 01-13-2007
  • 13-Jan-07
  • 13-01-07
  • Jan-13-07
  • 01-13-07
  • 10,000
  • 10,000.0
  • 10,000.00
  • 10,000.000
  • 10,000.0000
  • 10,000.00000
  • 10000
  • 10000,0
  • 10000,00
  • 10000,000
  • 10000,0000
  • 10000,00000
  • 10.000
  • 10.000,0
  • 10.000,00
  • 10.000,000
Width

The width of the Column in pixels.

Order

Numerical Order of the Column in regards to the other columns on the Browse Form.

Action Buttons Tab

Forms-Action.png

Add button

This Button will appear on The Browse Form and open a new/blank record in an Edit Form.

Save Button

This Button will appear on the Edit Form and can be hidden using the Display Condition if it is to be read only.

Functionality of this button is to commit changes to the selected record.

A record can be automatically checked, prior to saving, to see if any other user has edited it since this user started viewing it.

action buttons Fig 2. Warning message

To do this there must be the following fields added to the structure of the table being edited.

ALTER TABLE ??  
ADD ??_log_added_at DATETIME NOT NULL,  
ADD ??_log_added_by VARCHAR(25) NOT NULL,
ADD ??_log_changed_at DATETIME NOT NULL,  
ADD ??_log_changed_by VARCHAR(25) NOT NULL,
ADD ??_log_viewed_at DATETIME NOT NULL,  
ADD ??_log_viewed_by VARCHAR(25) NOT NULL

These fields need to be added to a table for changed records to be noticed. (Replace ?? with the table name)

Delete Button

This Button will appear on the Edit Form and can be hidden using the Display Condition if it is to be read only.

Functionality of this button is to delete the selected record

Clone Button

This Button will appear on the Edit Form and will be hidden until a record has been saved at least once..

Functionality of this button is to create a duplicate object with the same fields ready for editing

New Button

This Button will appear on the Edit Form and work as a combination of the Save and Add Buttons.

Print Button

This Button will appear on The Browse Form and will open a new window displaying an html table that is Formatted, Sorted and Filtered version of the Browse Form (all in one page). Fields Title: A customized title for that Button. Display Conditions: An SQL statement (that can include hash variables) that returns a text '0' (hide button) or '1' (display button)

Extra Action Buttons Tab

Forms-Extra-Action.png


Extra Action Buttons can be created that will appear on the Edit Form in the same area as Action Buttons.

The main difference between Action Buttons and Extra Action Buttons is an Extra Action Button can run customized code.

Title

Defines the text that will be displayed on the button.

Display Conditions

SQL statement (that can include hash variables) that returns a text '0' (hide button) or '1' (display button)

Javascript to Run

Javascript that will run once this button has been clicked.

Custom Code Tab

Form events.PNG

Invoking the syntax checking editor

Before Browse

PHP Code that will be executed before a Browse Form is displayed.

Can use Hash Variables.

Before Open

PHP Code that will be executed before an Edit Form is displayed.

Can use Hash Variables.

Before Save

PHP Code that will be executed before an Edit Form record is saved.

Can use Hash Variables.

For example we can use the following PHP code to ensure that the user hasn't changed any of the values manually using a Javascript console.

Take note of the use of the $nuHash variable to obtain the current value of the field on the form. This is generally only required when the user is accessing a subform.

//fetch all of the prefixes for the subform.
$arr = nuSubformArray('inv_items');
$total = 0; 

//go through each of the rows in the subform (except the last one) and make sure that the data is consistent. 
for( $idx = 0; $idx < count($arr)-1; $idx++ ) {
    $sql = "
        SELECT cpr_cost
        FROM customer_price
        WHERE customer_price_id = ?
        AND cpr_customer_id = ?
    ";  
  
    //we can use the hash variable for the inv_customer_id as the customer will not change.
    $search = array($nuHash[$arr[$idx].'ini_customer_price_id'], '#inv_customer_id#');  
    $qry = nuRunQuery($sql, $search);
    $res = db_fetch_object($qry);

    $cost = $res->cpr_cost;
    $total_item = $cost * $nuHash[$arr[$idx].'ini_units'];  
  
    if( $cost == '' ) {
        //No such item for the customer
        $MESSAGE = 'Current customer unable to purchase a selected item ';
        nuDisplayError($MESSAGE);
        return;
    }
    else if( $cost != $nuHash[$arr[$idx].'ini_price_unit'] ) {
        //Cost per unit item has been changed.
        $MESSAGE = 'The price for an item is not consistent';
        nuDisplayError($MESSAGE);
        return;
    }
    else if( $total_item != $nuHash[$arr[$idx].'ini_total'] ) {
        //Total price of item has been changed.   
        $MESSAGE = 'The total price for an item is not consistent';
        nuDisplayError($MESSAGE);
        return;
    }
    else {
        //this record is correct
        $sum += $total_item;
   }
} 

if( $sum != $nuHash['inv_total'] ) { 
    //The total cost of the invoice has been changed.
    $MESSAGE = 'The total cost of invoice is not consistent with the items chosen';
    nuDisplayError($MESSAGE);
    return;
}

Before Delete

PHP Code that will be executed before an Edit Form record is saved. (Same as Before Save)

Can use Hash Variables.

After Save

PHP Code that will be executed after an Edit Form record is saved.

    • Can use Hash Variables.

After Delete

PHP Code that will be executed after an Edit Form record is deleted.

    • Can use hash Variables.

Javascript

Javascript Code that sits within the current HTML document and can be triggered when a Form is created on the screen.

For example using a combination of the nuLoadBrowse function and the nuBrowseRows function we can highlight some rows in the browse form in some way. In this example we will change the colour of each of the rows to be green if the customer has an email address with gmail.

In the Javascript section of the Custom Code Tab of the customer form we place the following code:

function nuLoadBrowse() {
    var rows = nuBrowseRows();
    
    var row_len = rows.toString().length;
    var pad = "0000";
    
    for( var i = 0; i < rows; i++ ) {
        var rowString = i.toString();
        var rowNum = pad.substring(0, pad.length - rowString.length ) + rowString;
        var id = 'row_'+rowNum+'_col_2';
        if( $("div[id='"+id+"']").text().trim().match(/@gmail\.com$/) ) {
            $("div[id^='row_"+rowNum+"']").css("color", "green");
        }
    }
}

This will be run anytime that the Browse Form is loaded and will look through each of the rows on the browse form and if the email address ends with @gmail.com the text of the entire row will be changed to green. It is possible to take this further by having different colours of text having different meaning.

Reorder Form Objects Tab

Forms-Reorder.png

Objects

All of the Objects that are currently attached to this Edit Form. This allows you to edit any of the listed properties of objects that are currently on the form.

This can be used to modify the basic properties of multiple objects at once, an example of use is if you want to move the delivery address fields to a different tab. Instead of going into each of the objects seperately, it is possible to go to this tab and just modify the tab name and tab order of each of the fields.

Adding Objects

Rearranging Objects