# FormBuffer and FormBufferElement class

The FormBuffer and FormBufferElement class allow to transfer datas between DFrames.

They are stored in the ext/formBuffer.js file.

They are loaded with a classical include statement

<script language="Javascript" src=" ext/formBuffer/formBuffer.js "></script>

or by using the include function of DFrameAPI:

DFrameAPI.include('ext/formBuffer/formBuffer.js')

Those two classes, usable with very few modifications with " traditional " frames are not parts of dFrameAPI. The corresponding code is thus not scrambled in order to be adapted, improved or corrected.

They are used in 2 samples:

file: booksSample.html

Run the example

See the source code

file: timeReportSample.html

Run the example

See the source code

## FormBufferElement class

A FormBufferElement represents a field of a form contained in DFrame.

#### Syntax

var elt = new FormBufferElement(arguments)

arguments:

1 argument: Complete identification of a field in a page inserted in a DFrame.

3 arguments: DFrame name, name or number of form, fieldName

#### Properties

The properties of the class are:

FormBufferElement.name: The name of the field used to create the FormBufferElement.

FormBufferElement.type: The type of the field (test, textarea, checkbox ext. …)

FormBufferElement.value: The value of the field

FormBufferElement.checked: The property checked of the field, if radiobutton or checkbox

FormBufferElement.selectedIndex: The property of the field, if it is about a list.

Example:

Instanciation with 1 argument:

var elt = new FormBufferElement(dFrame.window.document.forms[0].firstName)

alert(elt.value)

Instanciation with 3 arguments:

var elt = new FormBufferElement(dFrame, 0, 'firstName')

alert(elt.value)

## FormBuffer class

A FormBuffer represents all elements of a form contained in DFrame.

A FormBuffer is an array of FormBufferElement

var reportBuffer = new FormBuffer()

reportBuffer.updateElements(dFrame, 0)

for (var i = 0 ; i< reportBuffer.elements.length ; i++) {

var elt = reportBuffer.elements[i]

alert(elt.value)

}

One of the possible arguments of some methods of the FormBuffer class is the session identifier: The elements can be created in a FormBuffer object with an identifier and, this identifier being indicated during the extraction, only the corresponding elements will be restored.

Example :

var reportBuffer = new FormBuffer()

…

//From a first DFrame add elements to reportBuffer

var sessionID1 = 1

reportBuffer.addElements(dFrame1, 0, sessionID1)

//From another DFrame add elements to reportBuffer

var sessionID2 = 2

reportBuffer.addElements(dFrame2, 0, sessionID2)

…

//Data of the first DFrame have been modified

//Update them without mistake, even if some fields

//of dFrame1 and dFrame2 have the same name

reportBuffer.updateElements(dFrame, 0, sessionID1)

Constructor :

new FormBuffer()

Example :

var reportBuffer = new FormBuffer()

FormBuffer.prototype.resetElements

Reset all elements of a FormBuffer

Example :

reportBuffer.resetElements()

FormBuffer.prototype.updateElements

Update existing elements of a FormBuffer and/or create new elements.

Syntax :

1 argument: FormBufferElement: Update the element.

2 (+1) arguments: DFrame, nameOrNumber of form (+ sessionId): Update all elements of the form.

3 (+1) arguments: DFrame, nameOrNumber of form, fieldName (+ sessionId): Update the element corresponding to the field.

Example :

var reportBuffer = new FormBuffer()

var elt = new FormBufferElement(dFrame.window.document.forms[firstName])

if (elt.value != '') reportBuffer.updateElements(elt)

or

reportBuffer.updateElements(dFrame, 0, sessionID)

or

reportBuffer.updateElements(dFrame, 0, fieldName, sessionID)

FormBuffer.prototype.addElements

Add new elements in a FormBuffer.

Syntax :

1 (+1) argument: FormBufferElement or Array of FormBufferElement (+ sessionId)

2 (+1) arguments: DFrame, nameOrNumber of form (+ sessionId)

3 (+1) arguments: DFrame, nameOrNumber of form, fieldName (+ sessionId)

Example :

var reportBuffer = new FormBuffer()

var elt = new Array()

elt[0] = new FormBufferElement(dFrame.window.document.forms[firstName])

elt[1] = new FormBufferElement(dFrame.window.document.forms[lastName])

reportBuffer.updateElements(elt)

or

reportBuffer.addElements(dFrame, 0, sessionID)

or

reportBuffer.addElements(dFrame, 0, fieldName, sessionID)

FormBuffer.prototype.removeElements

Delete elements from a FormBuffer.

1 argument: FormBufferElement

2 (+1) arguments: DFrame, nameOrNumber of form (+ sessionId)

3 (+1) arguments: DFrame, nameOrNumber of form, fieldName (+ sessionId)

FormBuffer.prototype.updateForm

Copy elements from a FormBuffer to a form.

The name of elements must match with the names of fields.

If many elements of the FormBuffer have the same name (regarding a correct sessionId) the last created is used.

Syntax:

2 (+1) arguments: DFrame, nameOrNumber of form (+ sessionId)

3 (+1) arguments: DFrame, nameOrNumber of form, fieldName or FormBufferElement (+ sessionId)

Example :

var reportBuffer = new FormBuffer()

//Copy elements of form in dFrame1 to reportBuffer

reportBuffer.updateElements(dFrame1, 0)

//Update form in dFrame2 from reportBuffer

reportBuffer.updateForm(dFrame2, 0)

FormBuffer.prototype.resetForm

Reset all fields of a form.

Syntax:

1 argument: DFrame

2 arguments: DFrame, nameOrNumber of form

FormBuffer.prototype.getSessionsAsFormattedString

Returns all content of a FormBuffer as a string.

Syntax:

FormBuffer.getSessionsAsFormattedString(sep1, sep2, sep3)

Properties of each element are separated with the sep1 value between 2 '|'.

Element are separated with the sep2 value between 2 '|'.

Sessions are separated with the sep2 value between 2 '|'.

Example

FormBuffer.getSessionsAsFormattedString('#', '##', '###')

Returns:

Duration|#|text|#|4|#|null|#|null|##|
Account|#|select-one|#|AS-025 (Western Comp.)|#|null|#|1|##|
Comment|#|textarea|#||#|null|#|null|##|
Day|#|select-one|#|1|#|null|#|0|###|
Duration|#|text|#|3|#|null|#|null|##|
Account|#|select-one|#|AS-025 (Western Comp.)|#|null|#|1|##|
Comment|#|textarea|#||#|null|#|null|##|
Day|#|select-one|#|1|#|null|#|0|###|

(The line-feed between each field is only here for a better legibility)

FormBuffer.prototype.loadSessionsFromFormattedString

Loads FormBuffer from a string.

Syntax

FormBuffer.loadSessionsAsFormattedString(sep1, sep2, sep3)

The string must have been created according to the rules of the getSessionAsFormattedString method.

Note: 2 methods will be added in a later release:

FormBuffer.prototype.getSessionsAsXML

FormBuffer.prototype.loadSessionsFromXML