title: Joomla Insert Media form element via ajax
body: <p>I am building a custom Joomla 3.0 administrator component and part of it requires some ajax calls to insert various types of fields.</p>
  
  <p>I have been unable to insert a Media field though.</p>
  
  <p>For the regular inputs I've just created the html directly.
  For the editor I've used the following code (I've just pasted an extract):</p>
  
  <pre><code>$editor = JFactory::getEditor();
  $html .= $editor-&gt;display($name, $value, '100%', '250px', 20, 20, true, $id);
  echo $html;
  </code></pre>
  
  <p>I would prefer not to recreate the html code for the Media field as there is a fair amount of html and javascript which could potentially change in future versions of Joomla.  Is there a method similar to the JFactory:getEditor() I could use?</p>
  
  <p>I've also tried creating an instance of the Media class but it requires a form object which I don't think is accessible (or at least I don't know how to fetch it) when doing the ajax call.</p>
  
  <pre><code>$xml = '&lt;field
      name="test"
      type="media"                        
  /&gt;';
  $field = new SimpleXMLElement($xml);
  
  $media = new JFormFieldMedia();
  $media-&gt;setup($field,'');
  
  echo $media-&gt;input;
  </code></pre>