title: Adding options dynamically , selected and not selected
body: <p>In <a href="https://github.com/Hemant411/dynamic-form" rel="nofollow noreferrer">this code</a> I want to inject options. How can I pass that using the <code>inject</code> function? Also pass in case some option is already selected.</p>
  <pre><code>dynamic_form.inject([{
    p_name: ['One','two'],
    quantity: '123',
    remarks: 'testing remark'
  }, {
    p_name: ['One','two'],
    quantity: '123',
    remarks: 'testing remark'
  }]);
  </code></pre>
  <p>This part of JSON is a bit confusing</p>
  <pre class="lang-js prettyprint-override"><code>$.each(formValue, function(index, value) {
    if ($.isArray(value)) {
      mainForm = clone.find(&quot;#&quot; + index);
      if (typeof mainForm.get(0).getSource === &quot;function&quot;) {
        $.each(value, $.proxy(fillData, mainForm.get(0).getSource()));
      }
    } else {
      var formElements = changeArray[formIndex].find(&quot;[origname='&quot; + index + &quot;']&quot;);
      if (formElements) {
        if (formElements.get(0).tagName.toLowerCase() == &quot;input&quot;) {
          /* Fill in radio input */
          if (formElements.attr(&quot;type&quot;) == &quot;radio&quot;) {
            formElements.filter(&quot;[value='&quot; + value + &quot;']&quot;).attr(&quot;checked&quot;, &quot;checked&quot;);
          } else if (formElements.attr(&quot;type&quot;) == &quot;checkbox&quot;) { /* Fill in checkbox input */
            formElements.attr(&quot;checked&quot;, &quot;checked&quot;);
          } else {
            formElements.attr(&quot;value&quot;, value);
          }
        } else if (formElements.get(0).tagName.toLowerCase() == &quot;textarea&quot;) {
          /* Fill in textarea */
          formElements.text(value);
        } else if (formElements.get(0).tagName.toLowerCase() == &quot;select&quot;) {
          /* Fill in select */
          $(formElements.get(0)).find(&quot;option&quot;).each(function() {
            if ($(this).text() == value || $(this).attr(&quot;value&quot;) == value) {
              $(this).attr(&quot;selected&quot;, &quot;selected&quot;);
            }
          });
        }
      }
    }
  });
  </code></pre>