IE7 и IE6 не передают параметры в form_tag в Rails - PullRequest
0 голосов
/ 09 февраля 2011

Самая странная ошибка, которую я когда-либо встречал. Шучу, но определенно наверху.

Если бы я создал динамическую форму, как это ..

= form_tag main_index_path, :method => :post do
  .payment
    = text_field_tag "payments[0][:date_paid]"
    = text_field_tag "payments[0][:amount_paid]"
    %br/
  = link_to 'Add Another Payment', '#', :class => "add_another"

  .actions
    %br/
    = submit_tag 'calculate'

И нажмите на 'Add Another Payment'

Новый div .payment будет выглядеть так:

.payment
  = text_field_tag "payments[1][:date_paid]"
  = text_field_tag "payments[1][:amount_paid]"

Как ни странно, только в IE6 и IE7, он будет пропускать только первые и последние платежей

Как / Почему / Что я могу сделать, чтобы это исправить?

Для справки, вот метод 'add_another':

$(".add_another").click(function(){
  if ($(".payment:last").find("input").val() != "") {
    var $newdiv = $(".payment:last").clone(true);
    $newdiv.find('input').each(function() {
        var $this = $(this);
        $this.attr('id', $this.attr('id').replace(/_(\d+)_/, function($0, $1) {
            return '_' + (+$1 + 1) + '_';
        }));
        $this.attr('name', $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
            return '[' + (+$1 + 1) + ']';
        }));
        $this.val('');
    });
    $newdiv.find('textarea').each(function(){
      var $this = $(this);
      $this.attr('id', $this.attr('id').replace(/_(\d+)_/, function($0, $1) {
          return '_' + (+$1 + 1) + '_';
      }));
      $this.attr('name', $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
          return '[' + (+$1 + 1) + ']';
      }));
      $this.css("color","#cccccc");
    });
    $newdiv.insertAfter('.payment:last').hide().slideDown();
  };
  return false;
});

Ответы [ 2 ]

1 голос
/ 09 февраля 2011

Странно, что вы получаете первые и последние платежи .. Это длинный путь, но, будучи IE ..

Есть ли способ проверить, правильно ли работает ваш insertAfter в этом CSSселектор .selector: last - на самом деле выбор нового последнего элемента в вашей группе?

Я не проверял это, но что произойдет, если вы замените:

$newdiv.insertAfter('.payment:last').hide().slideDown();

с этим:

$(".payment").last().after($newdiv).hide().slideDown();
0 голосов
/ 09 февраля 2011

IE7 требует клонирования с использованием OuterHTML

      var $this = $(this);
      if (!$.browser.msie || parseInt($.browser.version) > 7) {
        $this.attr('id', $this.attr('id').replace(/_(\d+)_/, function($0, $1) {
            return '_' + (+$1 + 1) + '_';
        }));
        $this.attr('name', $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
            return '[' + (+$1 + 1) + ']';
        }));
      } else {
        foob_name = $this.attr('name').replace(/\[(\d+)\]/, function($0, $1) {
            return '[' + (+$1 + 1) + ']';
        });
        foob_id = $this.attr('id', $this.attr('id').replace(/_(\d+)_/, function($0, $1) {
            return '_' + (+$1 + 1) + '_';
        }));

        $this.attr("outerHTML", "<input type='test' name=" + foob_name + " id=" + foob_id + " />");

      };
...