模态表单在没有单击表单的情况下消失

时间:2013-11-30 06:31:21

标签: javascript jquery html forms twitter-bootstrap

我们有一个正常工作的表单并正确提交。当我将表单转换为模态(引导程序)时出现问题。当表单呈现时,用户可以通过Tab键并输入就好了。选择框工作,可以按键盘输入;但是,当我使用鼠标并单击包含背景的模态上的任何元素时,它会消失。请帮忙。这是代码:

    $('#new_event').click( function() {
      $('#all-events').toggle(false);
      $('#all-invitations').toggle(false);
      $('#friend-requests').toggle(false);
      $('#feed').toggle(false);
      $('#time-select-start').toggle(false);
      $('#time-select-end').toggle(false);
      $('#event-type-select').toggle(false);
      $('#event_location').val('Current Location');
      $('#event_location').attr('readonly',true);
      $('#new-event').toggle();
      check_dashboard();
    });

观点:

%a{'href' => '#new-event','data-toggle' => 'modal', 'class' => 'btn btn-primary btn-small'}
      new event
:
:
#new-event{'class' => 'modal hide fade'}
      = render 'events/new_event'

以下是表格:

.modal-form
.fieldset
    .container
        %center
            .well.span6{:style => "position:relative; right:2.1%;background-color:#ffffff;"}

                %h1{:style => 'font-family:eight_one;font-weight:normal;color:#ff6699;'} quick rondé 
                = form_for(@event, html: { class: 'form-vertical' }) do |f|
                    %div
                        = f.text_field :name,:autofocus => 'true',:placeholder => "event name"
                    %div
                        = f.text_area :description, rows: 3, :placeholder => "give your friends some more details and convince them to come "
                    %div
                        = f.text_field :location,:placeholder => "location"
                    %div
                        = f.text_field :event_type, :placeholder => 'event type'
                    %ul.span3.dropdown-menu#event-select-type{:style => 'position:absolute; left:27.65%;top:63%;',"role" => "menu"}
                        %li
                            %a#Food{:href => '#'} food
                            %a#Drink{:href => '#'} drink
                            %a#Other{:href => '#'} other

                    %div
                        = f.text_field :start, :placeholder => 'start time'
                    %ul.span3.dropdown-menu#time-select-start{:style => 'position:absolute; left:27.65%;top:73%;',"role" => "menu"}
                        %li#time-list-start
                    %div
                        = f.text_field :end, :placeholder => 'end time'
                    %ul.span3.dropdown-menu#time-select-end{:style => 'position:absolute; left:27.65%;top:82%;',"role" => "menu"}
                        %li#time-list-end
                    %a{'data-dismiss' => 'modal'} Cancel        
                    = f.submit value: 'Create', class: 'btn btn-info' 

任何帮助都会很棒。我是javascript,haml和modals的新手...谢谢。

1 个答案:

答案 0 :(得分:0)

您是否尝试阻止表单上的默认操作?

    $(document).bind("modal-form",function(e){
     return false;
    });

或处理鼠标事件?

    $(".modal-form").mouseup(function(e){
      switch(e.which){
        case 1:
          left click event;
        break;
        case 2:
          middle click event;
        break;
        case 3:
          right click event;
        break;
        default:
          default action;
       }
      });