Skip to content
Stefan Meyer edited this page Dec 24, 2013 · 5 revisions

the data to be edited is internally converted into a special model. Reasons are:

  • Binding to plain javascript object is still difficult. There is no watch mecahnism until ES6.
  • the model is bound to the widget. For an array of primitives this is difficult to do because primitives are not objects. Therefore primitives are wrapped in objects. Also the user can change the type of an object. Instead of rebinding the object to different widgets there is an instance for each type which is bound to its own widget.

example for a plain value:

{
  name:"Will",
  street:"hight street"
}

corresponding model:

{
  state: "",
  value : {
   name :{
    value : "Will",
    oldValue:"Ben",
    state: "Error",
    message: "That is not his name"
   },
   street:{
    value : "hight street",
    oldValue:"low street",
    state: "Incomplete"
   }
 }

}

How to use the model

To retrieve the plainValue from the mode:

var value = model.getPlainValue();

To create a model from a plainValue you use the constructor. .

var model = new PrimitiveModel();
model.update(3);

predefined meta data in model

The model also contains meta data.

  • oldValue: the original value
  • state: "" if the value is valid. "Error" if the value is not valid. "Incomplete" if the value is empty, required but not touched by the user yet.
  • message: the error message if state is "Error"
Clone this wiki locally