     end
   end
 
+  defp escape_value(nil), do: nil
   defp escape_value(value) do
     Phoenix.HTML.html_escape(value) |> elem(1)
   end

    |> Xain.input
    build_errors(errors)
  end

  @doc false
  def build_has_many_fieldset(conn, res, fields, orig_inx, ext_name, field_field_name, model_name, errors) do

    build_errors(errors)
  end

  def build_control(Ecto.DateTime, resource, opts, model_name, field_name, ext_name, errors) do
    %{name: model_name, model: resource, id: model_name}
    |> datetime_select(field_name, Map.get(opts, :options, []))
  end

  def build_control(_type, resource, opts, model_name, field_name, ext_name, errors) do
    # Logger.debug "build_control type: #{inspect _type}"
    Map.put_new(opts, :type, :text)
    |> Map.put_new(:maxlength, "255")
    |> Map.put_new(:name, "#{model_name}[#{field_name}]")
