Comment 7 for bug 1018272

Revision history for this message
jon48 (genea-jaubart) wrote : Re: 1.3.0: edit_interface.php source citation autofill is taken from wrong souce

Hello,
Concerning the initial issue, it comes from the way the source value is called. It is indeed coded like: jQuery("input[class^=SOUR]").val(), but this will take only the first element which class starts with "SOUR", hence it is picking the first source value, and not the associated one.

I faced this issue for a personal module I have developed.
For information (I do not say this is the best implementation, and I find it myself not very clean), the way I have fixed it is creating ID with a fixed prefix for a specific fact and a random number shared by the fact we want to associate like for instance #SOUR28421415 and #PAGE28421415. Then I call the JavaScript :

$('.PAGE').each(function(i, el){ /* We are going to iterate through each SourcePage fact, based on the class */
  el = $(el);
  el.autocomplete({
   source: function(request, response) {
    $.ajax({
     url: 'autocomplete.php',
     datatype: 'json',
     data : {
      term : request.term,
      sid: $('#SOUR' + el.attr('id').substring(4)).val() /* el.attr('id').substring(4) takes the value of PAGE28421415 and extract the ID than concatenate with the prefix for sources*/
     },
     success: function(data) {
      response(data);
     },
              error: function(xhr, textStatus, errorThrown) {
                  alert('Error: ' + xhr.statusText);
              }
    });
   },
   delay:500,
   select: function(event, ui){
    el.val(ui.item.value);
    el.change();
   }
  });
 });

The above is adapted from my own code, so all parameters might not be useful, and uses a slightly different call than standard autocomplete, but I am sure the jQuery.getJSON fonction could be called, the important bit, being the iteration over the .PAGE class, the retrieval of the id, and then the concatenation to the SOUR prefix to retrieve the associated value.

Jonathan

Regards.