Javascript Object KDFFieldSet
From KallestadWiki
Contents |
Overview
Manages a data set
The KDFFieldSet enables application functions, manages AJAX based communication, tracks which fields are updated, and does basically everything that changes a regular web form into an interactive application environment.
Initialization
Creating a KDFFieldset object is a matter of simply calling new:
myFieldSet = new KDFFieldSet(params)
For a list of parameters, see the initialization function definition below.
Data Members
The following is a list of members of the KDFFieldSet object
- name - the name of the form containing the fields associated with the object
- fs - an array of form elements managed within the fieldset
- tester - to be removed
- fieldinfo - a hash of fieldinformation (see below)
- uid - the unique identifier for
- type - seems to always be KDFFieldSet... looking into it
- objectMap - a map of field id's to server side column names (see below)
- object - ?
- curobjid - The id of the object currently being edited
- mode - whether the form is prepared for KDF actions NEW, MODIFY, or BULKUPDATE modes
- children - an array of child KDFFieldSet objects
fieldinfo
The fieldinfo data member is an array of hashes. Each item in the array represents an individual field being managed by the KDFFieldSet object. Each hash value represents a property of that field.
fieldinfo[fieldid] =
$H({
id => field id
name => field name
dirtyflag => whether or not the field has been updated
})
objectMap
It is not always possible to match up field names/ids with what they need to be interpreted as server side - multiple fields could exist on a given page with the same identifier. Desired names/ids may posess a naming convention that is illegal client side. Other than that, perhaps the developer wants to provide the end user with field names/ids that are more relevant to the end user's perspective.
The objectMap element addresses this situation by providing a map of client-side field names to server side field names.
objectMap.FieldID = server side field id
or really
objectMap = $H{{
fieldid: serverid
... defined for every field
fieldid: serverid
})
Functions
add_field
Adds a form field to the KDFFieldSet Object. Any fields that were already members of the named form on initialization are automatically added to the fieldset, but any fields inserted via the DOM post initialization will have to be added manually.
Syntax:
myFieldSet.add_field(element);
where element is the DOM node of the form field
(or an object that has a name and id property to reference)
dirtify
- An event handler for setting the dirty flag for a given field
- A manually called function for setting the dirty flag for a given field
Syntax:
myFieldSet.dirtify(event); or myFieldSet.dirtify(element);
serialize
serializes and returns all of the dirty elements in a given fieldset in a format suitable for POSTing or as GET parameters (without the preceding ?). Elements are URI encoded with encodeURIComponent.
results = myFieldSet.serialize();
toJSON
serializes and returns a named associative array of all dirty elements in Javascript Object notation format.
Syntax
myFieldSet.toJSON()
cleanAll
Clears the dirty flag for all fields within a fieldset.
Syntax
myFieldSet.cleanAll();
dirtyAll
Sets the dirty flag for all fields contained within a given fieldset. Use this in combination with a serialization function to return all data for a form.
Syntax
myFieldSet.dirtyAll(); myFieldSet.toJSON();
updateJSON
insertJSON
deleteJSON
This and the preceding two functions perform appropriate (insert/update/delete) AJAX actions with the KDF server.
resetToNull
Clears all the values(empties the fields) in a given fieldset.
Syntax
myFieldSet.resetToNull();
setDefaults
If no defs parameter is specified, this function collects a set of default values for a given fieldset based on the current values of the fields. This is useful in situations where you are displaying a new record with an existing field set.
If a defs parameter is specified, default values are taken from the parameter - with any fields not included receiving a null value.
Syntax
myFieldSet.setDefaults(defs);
resetToDefault
Resets the associated fieldset to the default values (contained within the fieldset object).
Syntax
myFieldSet.resetToDefault();
getValuesFromObject
Sets the field values of a fieldset to the values defined in an object.
??need to look into this function a little bit more.
Syntax
myFieldSet.getValuesFromObject(objectid);
putValuesToObject
Funny. I have no idea what this does.
Syntax
myFieldSet.putValuesToObject();
initialize
Creates a new instance of a KDFFieldSet object.
Syntax
myFieldSet = new KDFFieldSet(FormName,UniqueID, ObjectMap,object);
Migrating the definition currently...
myFieldSet = new KDFFieldSet(id,Options);
id is a unique identifier for the fieldset.
Options consist of:
- form
- fieldinfo
- uid
- type
- objectMap
- object
- curobjid
- childElements
- name
form
If Form is provided, all of the fields inside the form declaration are added to the fieldset.
Kallestad Development Framework Topics
- KDF Home
- Project Overview
- Technical Information
- Licensing
