XForm

XForm

new XForm()

Source:

Members

NAMESPACES :object

Description:
  • Object of known namespaces uses in ODK XForms, with prefixes as used in this validator.

Source:

Object of known namespaces uses in ODK XForms, with prefixes as used in this validator.

Type:
  • object

binds :Array.<Node>

Source:
Type:
  • Array.<Node>

bindsWithCalc :Array.<Node>

Source:
Type:
  • Array.<Node>

formControls :Array.<Node>

Source:
Type:
  • Array.<Node>

groups :Array.<Node>

Source:
Type:
  • Array.<Node>

instances :Array.<Node>

Source:
Type:
  • Array.<Node>

items :Array.<Node>

Source:
Type:
  • Array.<Node>

repeats :Array.<Node>

Source:
Type:
  • Array.<Node>

setvalues :Array.<Node>

Source:
Type:
  • Array.<Node>

Methods

_cleanXPathException(error) → {Error|string}

Description:
  • Returns cleaned-up XPath Exception error string unless in debug mode.

Source:
Parameters:
Name Type Description
error Error

Error object

Returns:

cleaned up error message or original error object

Type
Error | string

_cleanXmlDomParserError(error) → {Error|string}

Description:
  • Returns a cleaned-up XmlDomParser error string unless in debug mode.

Source:
Parameters:
Name Type Description
error Error

Error object

Returns:

cleaned up error message or original error object

Type
Error | string

_extractModelStr() → {string|Document}

Description:
  • Inefficient method that ensures that the namespaces are included in their expected locations, so Enketo Core knows how to handle them.

Source:
Returns:

The XML content to apply the stylesheet to given as a string or a libxmljs document.

Type
string | Document

_getDom() → {JSDOM}

Description:
  • Returns a JSDOM instance of the XForm.

Source:
Returns:

JSDOM instance of the XForm

Type
JSDOM

_getExternalDataArray() → {Array.<{id: string}>}

Description:
  • Returns some dummy external data that can be used to instantiate a Form instance that requires external data.

Source:
Returns:

external data object with dummy content

Type
Array.<{id: string}>

_join(arr)

Description:
  • Joins an array of strings into a readable string.

Source:
Parameters:
Name Type Description
arr Array.<string>

array of strings

_nodeName(thing, attribute) → {string|null}

Description:
  • Returns the model node name that a provided element refers to.

Source:
Parameters:
Name Type Default Description
thing Element | string

The XForm element or path.

attribute string nodeset

The attribute that contains the path.

Returns:

the node name.

Type
string | null

_stripJrChoiceName(expr) → {string}

Description:
  • Strips jr:choice-name function.

    Since this is such a weird function that queries the body of the XForm, and cannot be evaluated in XPath, we just strip it out.

Source:
Parameters:
Name Type Description
expr string

The initial expression.

Returns:

expression after stripping.

Type
string

_withFormControl(bind) → {boolean}

Description:
  • Determines whether a <bind> element has corresponding input form control.

Source:
Parameters:
Name Type Description
bind Element

The XForm element.

Returns:

whether the provided bind has a matching form control

Type
boolean

_withoutFormControl(bind) → {boolean}

Description:
Source:
Parameters:
Name Type Description
bind Element

The XForm element.

Returns:

whether the provided bind has no matching form control

Type
boolean

checkAppearances() → {Result}

Description:
  • Checks if appearances are valid.

Source:
Returns:

Result object with warnings and errors.

Type
Result

checkBinds() → {Result}

Description:
  • Checks if binds are valid.

Source:
Returns:

Result object with warnings and errors.

Type
Result

checkOpenClinicaRules() → {Result}

Description:
  • Checks special OpenClinica rules.

Source:
Returns:

Result object with warnings and errors.

Type
Result

checkStructure() → {Result}

Description:
  • Checks if the structure is valid.

Source:
Returns:

Result object with warnings and errors.

Type
Result

enketoEvaluate(expr, typeopt, contextPathopt, tryNative) → {Array.<Element>}

Description:
  • Evaluates an XPath expression on the XForm's primary instance.

Source:
Parameters:
Name Type Attributes Default Description
expr string

The expression to evaluate.

type string <optional>
string

One of boolean, string, number, node, nodes.

contextPath string <optional>
null

Query selector.

tryNative boolean false

Whether it is safe to try the native evaluator (no date comparisons or calculations)

Returns:

an array of elements.

Type
Array.<Element>

getBind(nodeset) → {Node}

Description:
  • Returns a <bind> element with the provided nodeset attribute value.

Source:
Parameters:
Name Type Description
nodeset string

nodeset attribute value

Returns:

bind element matching the nodeset value

Type
Node

getSetvalue(ref) → {Node}

Description:
  • Returns a <setvalue> element with the provided ref attribute value.

Source:
Parameters:
Name Type Description
ref string

ref attribute value

Returns:

setvalue element matching the nodeset value

Type
Node

nodeExists(path) → {Element|null}

Description:
  • Obtains a node from the model from its simple path.

Source:
Parameters:
Name Type Description
path string

simple path to node

Returns:

the result element or null if not found

Type
Element | null

nsPrefixResolver(ns) → {string}

Description:
  • Returns namespace prefix for given namespace.

Source:
Parameters:
Name Type Description
ns string

One of predefined NAMESPACES.

Returns:

namespace prefix.

Type
string

parseModel()

Description:
  • Parses the Model

    The reason this is not included in the constructor is to separate different types of errors, and keep the constructor just for XML parse errors.

Source:

XForm

new XForm(xformStr, optionsopt)

Source:
Parameters:
Name Type Attributes Description
xformStr string

XForm content.

options module:validator~ValidateResult <optional>

Validation options.

Members

NAMESPACES :object

Description:
  • Object of known namespaces uses in ODK XForms, with prefixes as used in this validator.

Source:

Object of known namespaces uses in ODK XForms, with prefixes as used in this validator.

Type:
  • object

binds :Array.<Node>

Source:
Type:
  • Array.<Node>

bindsWithCalc :Array.<Node>

Source:
Type:
  • Array.<Node>

formControls :Array.<Node>

Source:
Type:
  • Array.<Node>

groups :Array.<Node>

Source:
Type:
  • Array.<Node>

instances :Array.<Node>

Source:
Type:
  • Array.<Node>

items :Array.<Node>

Source:
Type:
  • Array.<Node>

repeats :Array.<Node>

Source:
Type:
  • Array.<Node>

setvalues :Array.<Node>

Source:
Type:
  • Array.<Node>

Methods

_cleanXPathException(error) → {Error|string}

Description:
  • Returns cleaned-up XPath Exception error string unless in debug mode.

Source:
Parameters:
Name Type Description
error Error

Error object

Returns:

cleaned up error message or original error object

Type
Error | string

_cleanXmlDomParserError(error) → {Error|string}

Description:
  • Returns a cleaned-up XmlDomParser error string unless in debug mode.

Source:
Parameters:
Name Type Description
error Error

Error object

Returns:

cleaned up error message or original error object

Type
Error | string

_extractModelStr() → {string|Document}

Description:
  • Inefficient method that ensures that the namespaces are included in their expected locations, so Enketo Core knows how to handle them.

Source:
Returns:

The XML content to apply the stylesheet to given as a string or a libxmljs document.

Type
string | Document

_getDom() → {JSDOM}

Description:
  • Returns a JSDOM instance of the XForm.

Source:
Returns:

JSDOM instance of the XForm

Type
JSDOM

_getExternalDataArray() → {Array.<{id: string}>}

Description:
  • Returns some dummy external data that can be used to instantiate a Form instance that requires external data.

Source:
Returns:

external data object with dummy content

Type
Array.<{id: string}>

_join(arr)

Description:
  • Joins an array of strings into a readable string.

Source:
Parameters:
Name Type Description
arr Array.<string>

array of strings

_nodeName(thing, attribute) → {string|null}

Description:
  • Returns the model node name that a provided element refers to.

Source:
Parameters:
Name Type Default Description
thing Element | string

The XForm element or path.

attribute string nodeset

The attribute that contains the path.

Returns:

the node name.

Type
string | null

_stripJrChoiceName(expr) → {string}

Description:
  • Strips jr:choice-name function.

    Since this is such a weird function that queries the body of the XForm, and cannot be evaluated in XPath, we just strip it out.

Source:
Parameters:
Name Type Description
expr string

The initial expression.

Returns:

expression after stripping.

Type
string

_withFormControl(bind) → {boolean}

Description:
  • Determines whether a <bind> element has corresponding input form control.

Source:
Parameters:
Name Type Description
bind Element

The XForm element.

Returns:

whether the provided bind has a matching form control

Type
boolean

_withoutFormControl(bind) → {boolean}

Description:
Source:
Parameters:
Name Type Description
bind Element

The XForm element.

Returns:

whether the provided bind has no matching form control

Type
boolean

checkAppearances() → {Result}

Description:
  • Checks if appearances are valid.

Source:
Returns:

Result object with warnings and errors.

Type
Result

checkBinds() → {Result}

Description:
  • Checks if binds are valid.

Source:
Returns:

Result object with warnings and errors.

Type
Result

checkOpenClinicaRules() → {Result}

Description:
  • Checks special OpenClinica rules.

Source:
Returns:

Result object with warnings and errors.

Type
Result

checkStructure() → {Result}

Description:
  • Checks if the structure is valid.

Source:
Returns:

Result object with warnings and errors.

Type
Result

enketoEvaluate(expr, typeopt, contextPathopt, tryNative) → {Array.<Element>}

Description:
  • Evaluates an XPath expression on the XForm's primary instance.

Source:
Parameters:
Name Type Attributes Default Description
expr string

The expression to evaluate.

type string <optional>
string

One of boolean, string, number, node, nodes.

contextPath string <optional>
null

Query selector.

tryNative boolean false

Whether it is safe to try the native evaluator (no date comparisons or calculations)

Returns:

an array of elements.

Type
Array.<Element>

getBind(nodeset) → {Node}

Description:
  • Returns a <bind> element with the provided nodeset attribute value.

Source:
Parameters:
Name Type Description
nodeset string

nodeset attribute value

Returns:

bind element matching the nodeset value

Type
Node

getSetvalue(ref) → {Node}

Description:
  • Returns a <setvalue> element with the provided ref attribute value.

Source:
Parameters:
Name Type Description
ref string

ref attribute value

Returns:

setvalue element matching the nodeset value

Type
Node

nodeExists(path) → {Element|null}

Description:
  • Obtains a node from the model from its simple path.

Source:
Parameters:
Name Type Description
path string

simple path to node

Returns:

the result element or null if not found

Type
Element | null

nsPrefixResolver(ns) → {string}

Description:
  • Returns namespace prefix for given namespace.

Source:
Parameters:
Name Type Description
ns string

One of predefined NAMESPACES.

Returns:

namespace prefix.

Type
string

parseModel()

Description:
  • Parses the Model

    The reason this is not included in the constructor is to separate different types of errors, and keep the constructor just for XML parse errors.

Source: