def editable_field_html(klass, field_name, value, f, include_nil_selectors = false)
      # When editing a job the values are of the correct type.
      # When editing a dirmon entry values are strings.
      field = klass.fields[field_name.to_s]
      return unless field && field.type

      placeholder = field.default_val
      placeholder = nil if placeholder.is_a?(Proc)

      case field.type.name
      when 'Symbol', 'String', 'Integer'
        options = extract_inclusion_values(klass, field_name)
        str     = "[#{field.type.name}]\n".html_safe
        if options
          str + f.select(field_name, options, { include_blank: options.include?(nil) || include_nil_selectors, selected: value }, { class: 'selectize form-control' })
        else
          if field.type.name == 'Integer'
            str + f.number_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
          else
            str + f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
          end
        end
      when 'Hash'
        "[JSON Hash]\n".html_safe +
          f.text_field(field_name, value: value ? value.to_json : '', class: 'form-control', placeholder: '{"key1":"value1", "key2":"value2", "key3":"value3"}')
      when 'Array'
        options = Array(value)
        "[Array]\n".html_safe +
          f.select(field_name, options_for_select(options, options), { include_hidden: false }, { class: 'selectize form-control', multiple: true })
      when 'Mongoid::Boolean'
        name = "#{field_name}_true".to_sym
        value = value.to_s
        str  = '<div class="radio-buttons">'.html_safe
        str << f.radio_button(field_name, 'true', checked: value == 'true')
        str << ' '.html_safe + f.label(name, 'true')
        str << ' '.html_safe + f.radio_button(field_name, 'false', checked: value == 'false')
        str << ' '.html_safe + f.label(name, 'false')
        # Allow this field to be unset (nil).
        if include_nil_selectors
          str << ' '.html_safe + f.radio_button(field_name, '', checked: value == '')
          str << ' '.html_safe + f.label(name, 'nil')
        end

        str << '</div>'.html_safe
      else
        "[#{field.type.name}]".html_safe +
          f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
      end
    end
def editable_field_html(klass, field_name, value, f, include_nil_selectors = false)
      # When editing a job the values are of the correct type.
      # When editing a dirmon entry values are strings.
      field = klass.fields[field_name.to_s]
      return unless field && field.type

      placeholder = field.default_val
      placeholder = nil if placeholder.is_a?(Proc)

      case field.type.name
      when 'Symbol', 'String', 'Integer'
        options = extract_inclusion_values(klass, field_name)
        str     = "[#{field.type.name}]\n".html_safe
        if options
          str + f.select(field_name, options, { include_blank: options.include?(nil) || include_nil_selectors, selected: value }, { class: 'selectize form-control' })
        else
          if field.type.name == 'Integer'
            str + f.number_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
          else
            str + f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
          end
        end
      when 'Hash'
        "[JSON Hash]\n".html_safe +
          f.text_field(field_name, value: value ? value.to_json : '', class: 'form-control', placeholder: '{"key1":"value1", "key2":"value2", "key3":"value3"}')
      when 'Array'
        options = Array(value)
        "[Array]\n".html_safe +
          f.select(field_name, options_for_select(options, options), { include_hidden: false }, { class: 'selectize form-control', multiple: true })
      when 'Mongoid::Boolean'
        name = "#{field_name}_true".to_sym
        value = value.to_s
        str  = '<div class="radio-buttons">'.html_safe
        str << f.radio_button(field_name, 'true', checked: value == 'true')
        str << ' '.html_safe + f.label(name, 'true')
        str << ' '.html_safe + f.radio_button(field_name, 'false', checked: value == 'false')
        str << ' '.html_safe + f.label(name, 'false')
        # Allow this field to be unset (nil).
        if include_nil_selectors
          str << ' '.html_safe + f.radio_button(field_name, '', checked: value == '')
          str << ' '.html_safe + f.label(name, 'nil')
        end

        str << '</div>'.html_safe
      else
        "[#{field.type.name}]".html_safe +
          f.text_field(field_name, value: value, class: 'form-control', placeholder: placeholder)
      end
    end
Returns the editable field as html for use in editing dynamic fields from a Job class.