|
419 | 419 | break;
|
420 | 420 | case "select":
|
421 | 421 | elem = document.createElement("select");
|
422 |
| - var msl, ovm = [], cm, iCol; |
423 |
| - iCol = p.iColByName[options.name]; |
424 |
| - cm = p.colModel[iCol]; |
| 422 | + var msl, ovm = [], iCol = p.iColByName[options.name], cm = p.colModel[iCol], isSelected; |
425 | 423 | if (options.multiple === true) {
|
426 | 424 | msl = true;
|
427 | 425 | elem.multiple = "multiple";
|
428 | 426 | $(elem).attr("aria-multiselectable", "true");
|
429 |
| - } else { msl = false; } |
| 427 | + ovm = vl.split(","); |
| 428 | + ovm = $.map(ovm, function (n) { return $.trim(n); }); |
| 429 | + } else { |
| 430 | + msl = false; |
| 431 | + ovm[0] = $.trim(vl); |
| 432 | + } |
| 433 | + if (options.size === undefined) { |
| 434 | + options.size = msl ? 3 : 1; |
| 435 | + } |
430 | 436 | if (options.dataUrl !== undefined) {
|
431 | 437 | var rowid = null, postData = options.postData || ajaxso.postData;
|
432 | 438 | try {
|
|
441 | 447 | type: "GET",
|
442 | 448 | dataType: "html",
|
443 | 449 | data: $.isFunction(postData) ? postData.call($t, rowid, vl, String(options.name)) : postData,
|
444 |
| - context: { elem: elem, options: options, vl: vl, cm: cm, iCol: iCol }, |
| 450 | + context: { elem: elem, options: options, cm: cm, iCol: iCol, ovm: ovm }, |
445 | 451 | success: function (data, textStatus, jqXHR) {
|
446 |
| - var ovm1 = [], elem1 = this.elem, vl2 = this.vl, cm1 = this.cm, iCol1 = this.iCol, |
| 452 | + var ovm1 = this.ovm, elem1 = this.elem, cm1 = this.cm, iCol1 = this.iCol, |
447 | 453 | options1 = $.extend({}, this.options),
|
448 |
| - msl1 = options1.multiple === true, |
449 | 454 | a = $.isFunction(options1.buildSelect) ? options1.buildSelect.call($t, data, jqXHR, cm1, iCol1) : data;
|
450 | 455 | if (typeof a === "string") {
|
451 | 456 | a = $($.trim(a)).html();
|
452 | 457 | }
|
453 | 458 | if (a) {
|
| 459 | + //$(elem1).empty(); // ??? |
454 | 460 | $(elem1).append(a);
|
455 | 461 | setAttributes(elem1, options1, postData ? ["postData"] : undefined);
|
456 |
| - if (options1.size === undefined) { options1.size = msl1 ? 3 : 1; } |
457 |
| - if (msl1) { |
458 |
| - ovm1 = vl2.split(","); |
459 |
| - ovm1 = $.map(ovm1, function (n) { return $.trim(n); }); |
460 |
| - } else { |
461 |
| - ovm1[0] = $.trim(vl2); |
462 |
| - } |
463 |
| - //$(elem).attr(options); |
464 | 462 | setTimeout(function () {
|
| 463 | + var isSelected1; // undefined |
465 | 464 | $("option", elem1).each(function (i) {
|
466 | 465 | //if(i===0) { this.selected = ""; }
|
467 | 466 | // fix IE8/IE7 problem with selecting of the first item on multiple=true
|
468 | 467 | if (i === 0 && elem1.multiple) { this.selected = false; }
|
469 |
| - if ($.inArray($.trim($(this).text()), ovm1) > -1 || $.inArray($.trim($(this).val()), ovm1) > -1) { |
| 468 | + if ($.inArray($.trim($(this).val()), ovm1) > -1) { |
470 | 469 | this.selected = "selected";
|
| 470 | + isSelected1 = true; |
471 | 471 | }
|
472 | 472 | });
|
| 473 | + if (!isSelected1) { |
| 474 | + $("option", elem1).each(function (i) { |
| 475 | + if ($.inArray($.trim($(this).text()), ovm1) > -1) { |
| 476 | + this.selected = "selected"; |
| 477 | + } |
| 478 | + }); |
| 479 | + } |
473 | 480 | jgrid.fullBoolFeedback.call($t, options1.selectFilled, "jqGridSelectFilled", {
|
474 | 481 | elem: elem1,
|
475 | 482 | options: options1,
|
|
482 | 489 | }
|
483 | 490 | }, ajaxso || {}));
|
484 | 491 | } else if (options.value) {
|
485 |
| - var i; |
486 |
| - if (options.size === undefined) { |
487 |
| - options.size = msl ? 3 : 1; |
488 |
| - } |
489 |
| - if (msl) { |
490 |
| - ovm = vl.split(","); |
491 |
| - ovm = $.map(ovm, function (n) { return $.trim(n); }); |
492 |
| - } |
493 | 492 | if (typeof options.value === "function") { options.value = options.value(); }
|
494 |
| - var so, sv, ov, svv, svt, |
| 493 | + var i, so, sv, ov, optionInfos = [], optionInfo, |
495 | 494 | sep = options.separator === undefined ? ":" : options.separator,
|
496 | 495 | delim = options.delimiter === undefined ? ";" : options.delimiter,
|
497 | 496 | mapFunc = function (n, ii) { if (ii > 0) { return n; } };
|
|
502 | 501 | if (sv.length > 2) {
|
503 | 502 | sv[1] = $.map(sv, mapFunc).join(sep);
|
504 | 503 | }
|
505 |
| - ov = document.createElement("option"); |
506 |
| - // consider to trim BEFORE filling the options |
507 |
| - ov.value = sv[0]; |
508 |
| - ov.innerHTML = sv[1]; |
509 |
| - elem.appendChild(ov); |
510 |
| - svv = $.trim(sv[0]); |
511 |
| - svt = $.trim(sv[1]); |
512 |
| - if (!msl && (svv === $.trim(vl) || svt === $.trim(vl))) { |
513 |
| - ov.selected = "selected"; |
514 |
| - } |
515 |
| - if (msl && ($.inArray(svt, ovm) > -1 || $.inArray(svv, ovm) > -1)) { |
516 |
| - ov.selected = "selected"; |
517 |
| - } |
| 504 | + optionInfos.push({ |
| 505 | + value: sv[0], |
| 506 | + innerHtml: sv[1], |
| 507 | + selectValue: $.trim(sv[0]), |
| 508 | + selectText: $.trim(sv[1]) |
| 509 | + }); |
518 | 510 | }
|
519 | 511 | } else if (typeof options.value === "object") {
|
520 | 512 | var oSv = options.value, key;
|
521 | 513 | for (key in oSv) {
|
522 | 514 | if (oSv.hasOwnProperty(key)) {
|
523 |
| - ov = document.createElement("option"); |
524 |
| - ov.value = key; |
525 |
| - ov.innerHTML = oSv[key]; |
526 |
| - elem.appendChild(ov); |
527 |
| - if (!msl && ($.trim(key) === $.trim(vl) || $.trim(oSv[key]) === $.trim(vl))) { ov.selected = "selected"; } |
528 |
| - if (msl && ($.inArray($.trim(oSv[key]), ovm) > -1 || $.inArray($.trim(key), ovm) > -1)) { ov.selected = "selected"; } |
| 515 | + optionInfos.push({ |
| 516 | + value: key, |
| 517 | + innerHtml: oSv[key], |
| 518 | + selectValue: $.trim(key), |
| 519 | + selectText: $.trim(oSv[key]) |
| 520 | + }); |
| 521 | + } |
| 522 | + } |
| 523 | + } |
| 524 | + //$(elem).empty(); |
| 525 | + for (i = 0; i < optionInfos.length; i++) { |
| 526 | + optionInfo = optionInfos[i]; |
| 527 | + ov = document.createElement("option"); |
| 528 | + ov.value = optionInfo.value; |
| 529 | + ov.innerHTML = optionInfo.innerHtml; |
| 530 | + elem.appendChild(ov); |
| 531 | + if (!msl && optionInfo.selectValue === $.trim(vl)) { |
| 532 | + ov.selected = "selected"; |
| 533 | + isSelected = true; |
| 534 | + } |
| 535 | + if (msl && $.inArray(optionInfo.selectValue, ovm) > -1) { |
| 536 | + ov.selected = "selected"; |
| 537 | + isSelected = true; |
| 538 | + } |
| 539 | + } |
| 540 | + if (!isSelected) { |
| 541 | + for (i = 0; i < optionInfo.length; i++) { |
| 542 | + if (!msl && optionInfo.selectText === $.trim(vl)) { |
| 543 | + ov.selected = "selected"; |
| 544 | + } |
| 545 | + if (msl && $.inArray(optionInfo.selectText, ovm) > -1) { |
| 546 | + ov.selected = "selected"; |
529 | 547 | }
|
530 | 548 | }
|
531 | 549 | }
|
|
0 commit comments