title: How to manually set the value (and trigger the select event) to jQuery autocomplete
body: <p>I know there are a few questions about this, but I couldn't find anyone that sets the value and also triggers the select function.</p>
  
  <p>My code is:</p>
  
  <pre><code>$("#ux-selfservice-account-edit-nationality").autocomplete({
      source: countryList,
      minLength: 1,
      autoFocus: true,
      select: function(event, ui) {
          $(this).val(ui.item.label).attr("oid", ui.item.oid);
  
          var select = $(this).closest(".ux-selfservice-account-box-edit").find(".ux-selfservice-account-edit-dni-type");
          // Check if the user has selected a different country (against the site)
          if (ui.item.iataCode == options.countryCode) {
              $(select).find("option").show();
          }
          else {
              $(select).find("option:not([value='PAS']):not([value=''])").hide();
              if ($(select).val() != "PAS") $(select).val('');
          }
          return false;
      },
      focus: function(event, ui) {
          return false;
      },
      search: function(event, ui) {
          $(this).attr("oid", "0");
      }
  });
  </code></pre>
  
  <p>The countries list is something like this:</p>
  
  <pre><code>[
      {
          iataCode: "AR",
          label: "Argentina",
          value: "Argentina",
          oid: 28515
      },
      ....
  ]
  </code></pre>
  
  <p>As you can see I have a very small check in the select function, if the user selects a different country I hide or show some options from another select drop down.</p>
  
  <p>Now my problem is that sometimes I want the country to be set by javascript, so that the user sees the country name in the field, the oid is set to the attr and also checks the country.</p>
  
  <p>Now I am doing something like this..</p>
  
  <pre><code>$("#ux-selfservice-account-edit-nationality").val(getCountryName(profile.personalInfo.country)).attr("oid", profile.personalInfo.country);
  </code></pre>
  
  <p>But of course this is wrong and doesn't check the other validation. also I can't do the validation here because I don't have the countryCode (iataCode). I know I can find it in the list, but the point is to use the same function of the autocomplete..</p>