Hemi JavaScript Framework

Hemi.data.form

Description

The Form Service is used to represent form elements in a Virtual Form instead of a traditional HTML Form collection. Virtual Forms track values whether or not the backing element exists (or is rendered), and Virtual Form Elements may be aggregated as desired. With Application Spaces, Virtual Forms are aggregated at the space level.

Class Index

Hemi.data.form.XHTMLFormElement

version 3.1.9

An internal representation of a form element.

Index

Method Index

Methods

getElement

Returns the rendered HTML Form Element.

Syntax

o = getElement( )

Returns

o as object: HTML Form Element

getIsRendered

Returns true if the form elemnet is rendered.

Syntax

b = getIsRendered( )

Returns

b as boolean: Bit indicating whether the element is rendered.

getName

Returns the name of form element.

Syntax

t = getName( )

Returns

t as String: The name of form element.

getObjectId

Returns the id of the underlying XHTMLComponent

Syntax

i = getObjectId( )

Returns

i as String: The id of the XHTMLComponent.

getReferenceId

Returns the id of the reference implementor, such as an Engine object.

Syntax

i = getReferenceId( )

Returns

i as String: The id of the reference implementor.

getType

Returns the type of form element.

Syntax

t = getType( )

Returns

t as String: The type of form element.

getValue

Returns the value of form element.

Syntax

t = getValue( )

Returns

t as String: The value of form element.

Hemi.data.form.XHTMLForm

version 3.1.9

An internal representation of a form within the framework.

Index

Method Index

Methods

getElement

Returns the specified XHTMLFormElement object.

Syntax

e = getElement( i )

Parameters

Returns

e as XHTMLFormElement: XHTMLFormElement object.

getElementByName

Returns the specified XHTMLFormElement object.

Syntax

e = getElementByName( n )

Parameters

Returns

e as XHTMLFormElement: XHTMLFormElement object.

getElements

Returns an array of XHTMLFormElement objects.

Syntax

a = getElements( )

Returns

a as array: Array of XHTMLFormElement objects.

isElement

Returns true if the specified name exists.

Syntax

b = isElement( i )

Parameters

Returns

b as boolean: Bit indicating whether the specified object name exists.

static Hemi.data.form.service

version 3.1.9

Static implementation of serviceImpl.

Hemi.data.form.serviceImpl

version 3.1.9

Manage collection of form elements used within Engine and XHTMLComponent contexts.

Index

Example Index

Property Index

Method Index

Examples

Virtual Form Example #1

This example shows how a form field, bound as an XHTMLComponent, is virtualized through XHTMLFormComponent. This allows the form value to persist in a virtual form even though the node no longer exists.

Example Code

<!-- HTML Source -->
<div id = "oFields">
  <input type = "text" id = "oText" value = "example text" />
  <input type = "button" value = "Destroy the text field" onclick = "testXhtmlDestroy()" />
</div>

<!-- Script Source -->
window.onload = testXhtml;
var oX;
function testXhtml(){
  var oForm = Hemi.data.form.service;
  var o = document.getElementById("oText");
  /// Up-bind the component with the service
  /// Name the component 'My Text'
  /// And identify its form as 'MyForm'
  /// The HTML form it is in doesn't matter.
  /// 
  oX = Hemi.object.xhtml.newInstance(o,1,"My Text","MyForm",oForm,0,0);
  oX.post_init();
}
function testXhtmlDestroy(){

  // Destroy the component
  // And throw away the input field
  // This will automatically syncronize the field value
  //
  oX.destroy();
  oX = null;
  document.getElementById("oFields").innerHTML = 
  	"<input type = \"button\" value = \"Retrieve the form\" onclick = \"testXhtmlRecover()\" />";
}
function testXhtmlRecover(){
  document.getElementById("oFields").innerHTML = "";
  
  // And, make another field
  //
  var oI = document.createElement("input");
  oI.type = "text";
  oI.style.border = "2px solid #FF0000";
  document.getElementById("oFields").appendChild(oI);
  
  // Make another component
  //
  var oForm = Hemi.data.form.service;
  var oX = Hemi.object.xhtml.newInstance(oI,1,"My Text","MyForm",oForm,0,0);
  oX.post_init();
}

Properties

object_config

Object API structure for storing sub structures: object_config.pointers and object_config.status.

Syntax

object = object.object_config

object_id

Unique instance identifier.

Syntax

String = object.object_id

object_type

The type of this object.

Syntax

String = object.object_type

object_version

Version of the object class.

Syntax

String = object.object_version

ready_state

Object load and execution state. Follows: 0 unitialized, 1 through 3 variant, 4 ready, 5 destroyed.

Syntax

int = object.ready_state

Methods

addComponent

Adds an XHTMLComponent, creating a new XHTMLFormElement that can synchronize and retain data whether or not the HTML Form Element continues to exist.

Syntax

b = addComponent( x, ri, bi )

Parameters

Returns

b as boolean: Bit indicating whether the component was added.

clearDataForm

Clears or resets the specified form elements.

Syntax

b = clearDataForm( i, b, q )

Parameters

Returns

b as boolean: Returns true if the form was reset, false otherwise.

getElement

Returns the HTML Node corresponding to the specified name and form index.

Syntax

o = getElement( n, i )

Parameters

Returns

o as DOMNode: HTML Form Field Node.

getElements

Returns an array of visible or active form elements.

Syntax

a = getElements( i )

Parameters

Returns

a as array: Array of visible or active form elements.

getForm

Returns the specified XHTMLForm object.

Syntax

e = getForm( i )

Parameters

Returns

e as XHTMLForm: XHTMLForm object.

getFormByName

Returns the specified XHTMLForm object.

Syntax

e = getFormByName( n )

Parameters

Returns

e as XHTMLForm: XHTMLForm object.

getForms

Returns an array of XHTMLForm objects.

Syntax

a = getForms( )

Returns

a as array: Array of XHTMLForm objects.

getObjectId

Returns the unique id of the object.

Syntax

i = getObjectId( )

Returns

i as String: The unique object instance id.

getObjectType

Returns the type of the object.

Syntax

t = getObjectType( )

Returns

t as String: The type of the object instance.

getObjectVersion

Returns the version of the object.

Syntax

v = getObjectVersion( )

Returns

v as String: The version of the object instance.

getReadyState

Returns the state of the object.

Syntax

s = getReadyState( )

Returns

s as int: The object ready state.

getValue

Returns the value of the XHTMLFormElement. Checkbox values are bit, and multi-selects are arrays of selected values.

Syntax

v = getValue( n, i )

Parameters

Returns

v as variant: The value of the XHTMLFormElement.

getValue

Sets the value of the specified XHTMLFormElement.

Syntax

b = getValue( n, v, i )

Parameters

Returns

b as boolean: Bit indicating whether the value was set.

getXElement

Returns the XHTMLFormElement object corresponding to the specified name and form index.

Syntax

o = getXElement( n, i )

Parameters

Returns

o as XHTMLFormElement: XHTMLFormElement object.

isFieldNode

Returns a bit indicating whether the specified field matches a predefined list of recognizable fields or custom components.

Syntax

bField = isFieldNode( n )

Parameters

Returns

bField as boolean: Bit indicating whether the node is recognized by the form service.

isForm

Returns true if the specified name exists.

Syntax

b = isForm( i )

Parameters

Returns

b as boolean: Bit indicating whether the specified object name exists.

removeDataForm

Removes the XHTMLForm object.

Syntax

b = removeDataForm( v )

Parameters

Returns

b as boolean: Bit whether the form was removed.

resetAll

Clears all forms and form hashmaps data and pointers.

Syntax

void resetAll( )

resetDataForm

Resets the specified form elements to either their default state or their previous state.

Syntax

b = resetDataForm( i, q )

Parameters

Returns

b as boolean: Returns true if the form was reset, false otherwise.

synchronizeComponent

Synchronizes the XHTMLFormElement, XHTMLComponent, and the rendered HTML Field.

Syntax

o = synchronizeComponent( x, b, l, q, s )

Parameters

Returns

o as boolean: Bit indicating whether the field was synchronized.

validate

Validates the specified form field based on the specified validation pattern id. Uses the hemi.data.validator.service class.

Syntax

o = validate( n, w, i )

Parameters

Returns

o as boolean: Bit indicating whether the form field validated.

validateForm

Validates form fields based on the configured validation patterns. Uses the hemi.data.validator.service class.

Syntax

o = validateForm( fi, b )

Parameters

Returns

o as boolean: Bit indicating whether the form validated.