javascript - Data dismiss in modal being called twice on click -


i've been working modal gets dismissed when user clicks 'cancel' button. working fine until button developed bug. when click on 'cancel' button, modal dismissed, closes , opens again. 1 needs click dismiss button twice close modal.

this 'bootstrap' modal , haven't made changes js file. css , html have been tinkered with. on inspecting in browser, see following function being called twice.

<div class="modal-backdrop fade in"></div> 

how fix error? have no idea start! following modal code.

note: same error being encountered 'cross' aria label @ top-right corner of modal.

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mysmallmodallabel" aria-hidden="true">                          <div class="modal-dialog modal-sm">                            <div class="modal-content">                               <div class="modal-header">                               <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true">&times;</span></button>                               <h4 class="modal-title" id="mymodallabel"><b>why deleting book?</b></h4>                             </div>                                <!--modal body starts -->                               <div class="modal-body">                                  <div class="radio">                                   <label>                                       <input type="radio" name="optionsradios" id="optionsradios1" value="option1" checked>sold                                 </div>                                  <div class="radio">                                   <label>                                     <input type="radio" name="optionsradios" id="optionsradios2" value="option2">sold on site or elsewhere                                   </label>                                 </div>                                  <div class="radio">                                   <label>                                     <input type="radio" name="optionsradios" id="optionsradios2" value="option2">don't want sell                                   </label>                                 </div>                                  <div class="radio">                                   <label>                                     <input type="radio" name="optionsradios" id="optionsradios2" value="option2">lack of buyer interest                                   </label>                                 </div>                                  <div class="radio">                                   <label>                                     <input type="radio" name="optionsradios" id="optionsradios2" value="option2">vacation, break                                   </label>                                 </div>                                  <div class="radio">                                   <label>                                     <input type="radio" name="optionsradios" id="optionsradios2" value="option2">other reason                                   </label>                                 </div>                                </div>                               <!--modal body end -->                                <div class="modal-footer">                                 <button type="button" class="btn btn-primary">delete</button>                                 <button type="button" class="btn btn-default" data-dismiss="modal">cancel</button>                               </div>                            </div>                         </div>                       </div> 

html code button opens modal

<button type= "submit" class="dashbtn dashbtn-danger">edit</button><br> <button type= "button" class="dashbtn dashbtn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">delete</button> 

this happens when have more 1 modal in code share same class. prevent these type of situations, assign different ids modals , use id in data-target attribute. try this:

<button type="submit" class="dashbtn dashbtn-danger">edit</button> <br> <button type="button" class="dashbtn dashbtn-primary" data-toggle="modal" data-target="#bs-example-modal-sm">delete</button> 

and modal:

<div class="modal fade" id="bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mysmallmodallabel" aria-hidden="true">     <div class="modal-dialog modal-sm">         <div class="modal-content">             <div class="modal-header">                 <button type="button" class="close" data-dismiss="modal" aria-label="close"><span aria-hidden="true">&times;</span>                 </button>                 <h4 class="modal-title" id="mymodallabel"><b>why deleting book?</b></h4>             </div>             <!--modal body starts -->             <div class="modal-body">                 <div class="radio">                     <label>                         <input type="radio" name="optionsradios" id="optionsradios1" value="option1" checked>sold                 </div>                 <div class="radio">                     <label>                         <input type="radio" name="optionsradios" id="optionsradios2" value="option2">sold on site or elsewhere                     </label>                 </div>                 <div class="radio">                     <label>                         <input type="radio" name="optionsradios" id="optionsradios2" value="option2">don't want sell                     </label>                 </div>                 <div class="radio">                     <label>                         <input type="radio" name="optionsradios" id="optionsradios2" value="option2">lack of buyer interest                     </label>                 </div>                 <div class="radio">                     <label>                         <input type="radio" name="optionsradios" id="optionsradios2" value="option2">vacation, break                     </label>                 </div>                 <div class="radio">                     <label>                         <input type="radio" name="optionsradios" id="optionsradios2" value="option2">other reason                     </label>                 </div>             </div>             <!--modal body end -->             <div class="modal-footer">                 <button type="button" class="btn btn-primary">delete</button>                 <button type="button" class="btn btn-default" data-dismiss="modal">cancel</button>             </div>         </div>     </div> </div> 

just make sure assign different ids each modal , trigger each 1 using data-target="#foo"

look section on modal data attributes: bootstrap modals


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -