code: function($field, isNew = false) {
      let field = {}
      if ($field instanceof jQuery) {
        // get the default type etc & label for this field
        field.type = $field[0].dataset.type
        if (field.type) {
          // check for a custom type
          const custom = controls.custom.lookup(field.type)
          if (custom) {
            field = Object.assign({}, custom)
          } else {
            const controlClass = controls.getClass(field.type)
            field.label = controlClass.label(field.type)
          }
  
          // @todo: any other attrs ever set in aFields? value or selected?
        } else {
          // is dataType XML
          const attrs = $field[0].attributes
          if (!isNew) {
            field.values = $field.children().map((index, elem) => {
              return {
                label: $(elem).text(),
                value: $(elem).attr('value'),
                selected: Boolean($(elem).attr('selected')),
              }
            })
          }
  
          for (let i = attrs.length - 1; i >= 0; i--) {
            field[attrs[i].name] = attrs[i].value
          }
        }
      } else {
        field = Object.assign({}, $field)
      }
  
      if (!field.name) {
        field.name = nameAttr(field)
      }
  
      if (isNew && ['text', 'number', 'file', 'date', 'select', 'textarea', 'autocomplete'].includes(field.type)) {
        field.className = field.className || 'form-control'
      }
  
      const match = /(?:^|\s)btn-(.*?)(?:\s|$)/g.exec(field.className)
      if (match) {
        field.style = match[1]
      }
  
      if (isNew) {
        field = Object.assign({}, field, opts.onAddField(data.lastID, field))
        setTimeout(() => document.dispatchEvent(events.fieldAdded), 10)
      }
  
      appendNewField(field, isNew)
  
      d.stage.classList.remove('empty')
    }
docs: builds the standard formbuilder datastructure for a field definition