Class: EditableValueUtils

Oracle® JavaScript Extension Toolkit (JET)



oj. EditableValueUtils

  • 3.2.0
  • 0.6
JET Editable Component Utils


new EditableValueUtils()



<static> coerceDomValueForOption(option, domValue)

Coerces the dom value being used for the option, and throws error if invalid.
Name Type Description
option string name of the option.
domValue string | Object | boolean | number | null dom value that is being coerced to the option value
if domValue cannot be coerced appropriately

<static> initializeOptionsFromDom(props, constructorOptions, comp, postprocessCallback)

Called from component._InitOptions() with an array of options that the component might need to initialize from DOM (e.g., disabled, required, title, etc). This function loops through each of these and if the constructorOptions[option] is undefined, it tries to get the option from DOM. The constructorOptions hold the options that the page author sets on the component, usually via knockout bindings, and that takes precedence over DOM. e.g., value is a constructorOption and required is a DOM option in this example. If you have: e.g., required is both a constructorOption of false and a DOM of true. The constructorOption takes precedence.

IMPORTANT: Do not call this method after component has been created, since option values are mutated directly after that point.

The 'final' value an option uses/initializes from, can come from these places (in order of least to most likely) -
  1. component default - this is the widget default

  2. app default - this is what a page author defines for the value in the page/app

  3. dom value - if your option also has a dom attribute, this is the value set on element for component.

  4. constructor value - this is the value page author sets on the component binding

At the time _InitOptions is called, (1), (2) and (4) are merged, but this may not be the value a component wants for the option, especially when (4) is undefined. For example, if these values were set for a component -
(1) - 'foo'
(2) - 'bar'
(3) - 'lucy'
(4) - undefined

at the time _InitOptions is called, this.options.option is set to 'bar'. But because DOM value wins over app default or component default, the component needs to check if the constructor value was undefined and if so, set option to the dom value which is 'lucy' in this example. This is what this function does.
This method always defaults the value to be - this.options.option - because we think if neither (3) nor (4) is set, then the value from (2) should win.

Name Type Argument Description
props Object Array holding Object-literal that a component provides with the following properties that helps determine the final value for one or more options.
constructorOptions Object the options set on the component instance, often using component binding. (this is the value page author sets on the component binding)
comp Object component instance.
postprocessCallback Function <optional>
optional callback that will receive a map of initialized options for post-processing
Name Type Description
props.attribute string name of DOM attribute
props.option string | undefined name of the option if different from attribute name.
props.coerceDomValue Function | boolean | undefined if the DOM value is set and coercing the dom value is needed, then either set to boolean true, which uses the default coercion rules for common attributes (a), or provide a custom callback (b).

E.g., 'value' option for input number, input date etc. have special rules for coercing the value, so thse provide a custom callback. For common attributes like required and disabled, set the value to true so the default oj.EditableValueUtils#coerceDomValueForOption method gets used.

props.validateOption boolean | undefined if set to true, then it calls oj.EditableValueUtils.validateValueForOption method to validate the option.

<static> validateValueForOption(option, value)

Validates value set for the option and throws error if invalid.
Name Type Description
option string name of the option. Validates options common to all edtiableValue holders.
value string | Object | boolean | number | undefined of the option that is validated
if option value is invalid