Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SimpleType.addTypeDefaults

    Hi,

    Is there a way to extend method SimpleType.addTypeDefaults to include other attributes that should be copied from SimpleType to DataSourceField and ListGridField?

    I can think of width, length, required, nullReplacementValue, canGroupBy...

    #2
    My proposition is to add method addTypeDefaults(field, ds) to instances of SimpleType.
    This method (if it would be defined) could be call in SimpleType.addTypeDefaults to add some type-specific defaults.

    This way one can easly extend SimpleType even with inhertiance.

    Code:
       addTypeDefaults : function (field, ds) {
     
            if (field == null || field._typeDefaultsAdded) return;
            field._typeDefaultsAdded = true; // should only ever happen once per field
    
            // get the type definition, looking for locally defined type if a DataSource is passed
            // in
            var type = this.getType(field.type, ds);
            if (type == null) return;
    
            // hang the type definition itself on the field, since when formatters are called, they
            // need to be invoked on the type
            field._simpleType = type;
    
            // add the valueMap to the field
            if (field.valueMap == null) {
                var valueMap = this.getInheritedProperty(type, "valueMap", ds);
                if (valueMap != null) type.valueMap = field.valueMap = valueMap;
            }
            
            if (field.editorType == null) {
                var editorType = this.getInheritedProperty(type, "editorType", ds);
                if (editorType != null) type.editorType = field.editorType = editorType;
            }
    
            // add formatters / parsers
            
            var formatter = this.getInheritedProperty(type, "shortDisplayFormatter", ds)
            if (formatter != null) type.shortDisplayFormatter = field._shortDisplayFormatter = formatter;
            var formatter = this.getInheritedProperty(type, "normalDisplayFormatter", ds)
            if (formatter != null) type.normalDisplayFormatter = field._normalDisplayFormatter = formatter;
            // these aren't documented yet because they only get called by inline editing, not
            // normal forms
            var formatter = this.getInheritedProperty(type, "editFormatter", ds)
            if (formatter != null) type.editFormatter = field._editFormatter = formatter;
            var parser = this.getInheritedProperty(type, "parseInput", ds)
            if (parser != null) type.parseInput = field._parseInput = parser;
    
            // add validators
            var typeValidators = this.getValidators(type, ds);
            if (typeValidators != null) { // CHANGE: this is changed to skip "return"
        
              if (!field.validators) {
                
                  field.validators = typeValidators;
              } else {
                  // there are both field validators and type validators
                  if (!isc.isAn.Array(field.validators)) field.validators = [field.validators];
                  field.validators.addAsList(typeValidators);
                  this._reorderTypeValidator(field.validators);
              }
            } // CHANGE: this is changed to skip "return"
            
            // CHANGE: this is added
            if(typeof type.addTypeDefaults == "function") {
              type.addTypeDefaults(field, ds);
            }
        }

    Comment

    Working...
    X