dojox/form/manager/_NodeMixin.js

  • Provides:

    • dojox.form.manager._NodeMixin
  • Requires:

    • dojox.form.manager._Mixin in common
  • dojox.form.manager._NodeMixin

    • type
      Function
    • summary
      Mixin to orchestrate dynamic forms (works with DOM nodes).
    • description
      This mixin provideas a foundation for an enhanced form
      functionality: unified access to individual form elements,
      unified "onchange" event processing, and general event
      processing. It complements dojox.form.manager._Mixin
      extending the functionality to DOM nodes.
  • dojox.form.manager._NodeMixin.destroy

    • type
      Function
    • source: [view]
         for(var name in this.formNodes){
          dojo.forEach(this.formNodes[name].connections, dojo.disconnect);
         }
         this.formNodes = {};


         this.inherited(arguments);
    • summary
      Called when the widget is being destroyed
  • dojox.form.manager._NodeMixin.registerNode

    • type
      Function
    • parameters:
      • node: (typeof String|Node)
        A node, or its id
    • source: [view]
         if(typeof node == "string"){
          node = dojo.byId(node);
         }
         var name = registerNode.call(this, node);
         if(name){
          connectNode.call(this, name, getObserversFromNode.call(this, name));
         }
         return this;
    • summary
      Register a node with the form manager
    • return_summary
      Object:
      Returns self
    • chains:
      • registerNode: (call)
      • connectNode: (call)
  • dojox.form.manager._NodeMixin.unregisterNode

    • type
      Function
    • parameters:
      • name: (typeof String)
        Name of the to unregister
    • source: [view]
         if(name in this.formNodes){
          dojo.forEach(this.formNodes[name].connections, this.disconnect, this);
          delete this.formNodes[name];
         }
         return this;
    • summary
      Removes the node by name from internal tables unregistering
      connected observers
    • return_summary
      Object:
      Returns self
  • dojox.form.manager._NodeMixin.registerNodeDescendants

    • type
      Function
    • parameters:
      • node: (typeof String|Node)
        A widget, or its widgetId, or its DOM node
    • source: [view]
         if(typeof node == "string"){
          node = dojo.byId(node);
         }


         dojo.query("input, select, textarea, button", node).
          map(function(n){
           return registerNode.call(this, n, node);
          }, this).
          forEach(function(name){
           if(name){
            connectNode.call(this, name, getObserversFromNode.call(this, name));
           }
          }, this);


         return this;
    • summary
      Register node's descendants (form nodes) with the form manager
    • return_summary
      Object:
      Returns self
    • chains:
      • registerNode: (call)
      • connectNode: (call)
  • dojox.form.manager._NodeMixin.unregisterNodeDescendants

    • type
      Function
    • parameters:
      • node: (typeof String|Node)
        A widget, or its widgetId, or its DOM node
    • source: [view]
         if(typeof node == "string"){
          node = dojo.byId(node);
         }


         dojo.query("input, select, textarea, button", node).
          map(function(n){ return dojo.attr(node, "name") || null; }).
          forEach(function(name){
           if(name){
            this.unregisterNode(name);
           }
          }, this);


         return this;
    • summary
      Unregister node's descendants (form nodes) with the form manager
    • return_summary
      Object:
      Returns self
  • dojox.form.manager._NodeMixin.formNodeValue

    • type
      Function
    • parameters:
      • elem: (typeof String|Node|Array)
        Form element's name, DOM node, or array or radio nodes.
      • value: (typeof Object)
        Optional. The value to set.
    • source: [view]
         var isSetter = arguments.length == 2 && value !== undefined, result;


         if(typeof elem == "string"){
          elem = this.formNodes[elem];
          if(elem){
           elem = elem.node;
          }
         }


         if(!elem){
          return null; // Object
         }


         if(dojo.isArray(elem)){
          // input/radio array
          if(isSetter){
           dojo.forEach(elem, function(node){
            node.checked = "";
           });
           dojo.forEach(elem, function(node){
            node.checked = node.value === value ? "checked" : "";
           });
           return this; // self
          }
          // getter
          dojo.some(elem, function(node){
           if(node.checked){
            result = node;
            return true;
           }
           return false;
          });
          return result ? result.value : ""; // String
         }
         // all other elements
         switch(elem.tagName.toLowerCase()){
          case "select":
           if(elem.multiple){
            // multiple is allowed
            if(isSetter){
             if(dojo.isArray(value)){
              var dict = {};
              dojo.forEach(value, function(v){
               dict[v] = 1;
              });
              dojo.query("> option", elem).forEach(function(opt){
               opt.selected = opt.value in dict;
              });
              return this; // self
             }
             // singular property
             dojo.query("> option", elem).forEach(function(opt){
              opt.selected = opt.value === value;
             });
             return this; // self
            }
            // getter
            var result = dojo.query("> option", elem).filter(function(opt){
             return opt.selected;
            }).map(function(opt){
             return opt.value;
            });
            return result.length == 1 ? result[0] : result; // Object
           }
           // singular
           if(isSetter){
            dojo.query("> option", elem).forEach(function(opt){
             opt.selected = opt.value === value;
            });
            return this; // self
           }
           // getter
           return elem.value || ""; // String
          case "button":
           if(isSetter){
            elem.innerHTML = "" + value;
            return this;
           }
           // getter
           return elem.innerHTML;
          case "input":
           if(elem.type.toLowerCase() == "checkbox"){
            // input/checkbox element
            if(isSetter){
             elem.checked = value ? "checked" : "";
             return this;
            }
            // getter
            return Boolean(elem.checked);
           }
         }
         // the rest of inputs
         if(isSetter){
          elem.value = "" + value;
          return this;
         }
         // getter
         return elem.value;
    • summary
      Set or get a form element by name.
    • return_summary
      Object:
      For a getter it returns the value, for a setter it returns
      self. If the elem is not valid, null will be returned.
    • returns
      Object|self|String
  • dojox.form.manager._NodeMixin.inspectFormNodes

    • type
      Function
    • parameters:
      • inspector: (typeof Function)
        A function to be called on a form element. Takes three arguments: a name, a node or
        an array of nodes, and a supplied value. Runs in the context of the form manager.
        Returns a value that will be collected and returned as a state.
      • state: (typeof Object)
        Optional. If a name-value dictionary --- only listed names will be processed.
        If an array, all names in the array will be processed with defaultValue.
        If omitted or null, all form elements will be processed with defaultValue.
      • defaultValue: (typeof Object)
        Optional. The default state (true, if omitted).
    • source: [view]
         var name, result = {};


         if(state){
          if(dojo.isArray(state)){
           dojo.forEach(state, function(name){
            if(name in this.formNodes){
             result[name] = inspector.call(this, name, this.formNodes[name].node, defaultValue);
            }
           }, this);
          }else{
           for(name in state){
            if(name in this.formNodes){
             result[name] = inspector.call(this, name, this.formNodes[name].node, state[name]);
            }
           }
          }
         }else{
          for(name in this.formNodes){
           result[name] = inspector.call(this, name, this.formNodes[name].node, defaultValue);
          }
         }


         return result; // Object
    • summary
      Run an inspector function on controlled form elements returning a result object.
    • returns
      Object
  • dojox.form.manager._NodeMixin.formNodes

    • summary
  • aa

    • summary
  • keys

    • summary
  • ce

    • summary
  • registerNode

    • type
      Function
    • parameters:
      • node: (typeof )
      • groupNode: (typeof )
    • source: [view]
         var name = dojo.attr(node, "name");
         groupNode = groupNode || this.domNode;
         if(name && !(name in this.formWidgets)){
          // verify that it is not part of any widget
          for(var n = node; n && n !== groupNode; n = n.parentNode){
           if(dojo.attr(n, "widgetId") && dijit.byNode(n) instanceof dijit.form._FormWidget){
            // this is a child of some widget --- bail out
            return null;
           }
          }
          // register the node
          if(node.tagName.toLowerCase() == "input" && node.type.toLowerCase() == "radio"){
           var a = this.formNodes[name];
           a = a && a.node;
           if(a && dojo.isArray(a)){
            a.push(node);
           }else{
            this.formNodes[name] = {node: [node], connections: []};
           }
          }else{
           this.formNodes[name] = {node: node, connections: []};
          }
         }else{
          name = null;
         }
         return name;
    • summary
  • getObserversFromNode

    • type
      Function
    • parameters:
      • name: (typeof )
    • source: [view]
         var observers = {};
         aa(function(_, n){
          var o = dojo.attr(n, "observer");
          if(o && typeof o == "string"){
           dojo.forEach(o.split(","), function(o){
            o = dojo.trim(o);
            if(o && dojo.isFunction(this[o])){
             observers[o] = 1;
            }
           }, this);
          }
         }).call(this, null, this.formNodes[name].node);
         return keys(observers);
    • summary
  • connectNode

    • type
      Function
    • parameters:
      • name: (typeof )
      • observers: (typeof )
    • source: [view]
         var t = this.formNodes[name], c = t.connections;
         if(c.length){
          dojo.forEach(c, dojo.disconnect);
          c = t.connections = [];
         }
         aa(function(_, n){
          // the next line is a crude workaround for dijit.form.Button that fires onClick instead of onChange
          var eventName = ce(n);
          dojo.forEach(observers, function(o){
           c.push(dojo.connect(n, eventName, this, function(evt){
            if(this.watching){
             this[o](this.formNodeValue(name), name, n, evt);
            }
           }));
          }, this);
         }).call(this, null, t.node);
    • summary
  • dojox.form.manager

    • type
      Object
    • summary
  • dojox.form

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary