MediaWiki:Common.js: Difference between revisions

From TANGOWIKI-TITAF
No edit summary
No edit summary
Line 1: Line 1:
mw.loader.using('jquery').done(function () {
$(document).ready(function () {
  $(document).ready(function () {
  $('select[name="Tune[Composer][is_list]"], select[name="Tune[Lyricist][is_list]"]').on('select2:select', function (e) {
    setTimeout(function () {
    var selected = e.params.data.text;
      // Target Composer and Lyricist token fields
    var match = selected.match(/\((TITAF-[^)]+)\)$/); // extracts TITAF-P-xxxxxxx
      $('select[name="Recording[Composer][]"], select[name="Recording[Lyricist][]"]').on('select2:select', function () {
    if (match) {
        const $select = $(this);
      var newVal = match[1]; // TITAF-P-xxxxxxx
 
      var newOption = new Option(newVal, newVal, true, true);
        setTimeout(function () {
      $(this).append(newOption).trigger('change');
          $select.find('option:selected').each(function () {
      var oldOption = $(this).find('option').filter(function () {
            const label = $(this).text();
         return $(this).text() === selected;
            const match = label.match(/\((TITAF-P-\d+)\)$/); // Look for pattern: (TITAF-P-1234567)
            if (match) {
              const id = match[1];
              $(this).text(id).val(id);
            }
          });
         }, 50);
       });
       });
     }, 500);
      oldOption.remove();
     }
   });
   });
});
});

Revision as of 21:03, 26 May 2025

$(document).ready(function () {
  $('select[name="Tune[Composer][is_list]"], select[name="Tune[Lyricist][is_list]"]').on('select2:select', function (e) {
    var selected = e.params.data.text;
    var match = selected.match(/\((TITAF-[^)]+)\)$/); // extracts TITAF-P-xxxxxxx
    if (match) {
      var newVal = match[1]; // TITAF-P-xxxxxxx
      var newOption = new Option(newVal, newVal, true, true);
      $(this).append(newOption).trigger('change');
      var oldOption = $(this).find('option').filter(function () {
        return $(this).text() === selected;
      });
      oldOption.remove();
    }
  });
});