Rectangle 27 1

You need to wire up the click events to the href's when the new dynamic content has been loaded into the DOM.

When the page loads, JQuery will look through the DOM for your $("#TestButton") and find nothing as at the time when this happens the dynamic content has yet to be injected.

There are a couple of ways of handling this... firstly you can delay the wire up of the click events with JQuery until the new content has been injected, or you can use the .live function of JQuery.

$("#TestButton").live('click', function (ev) {
        ev.preventDefault()

        alert('Test Button Clicked'); 
    });

Actually... it seems Live has been depreciated as of JQuery 1.7

$("#TestButton").on('click', function (ev) {
            ev.preventDefault()

            alert('Test Button Clicked'); 
        });

asp.net mvc - Accessing twitter bootstrap modal-body content with jque...

jquery asp.net-mvc twitter-bootstrap modal-dialog
Rectangle 27 1

You need to wire up the click events to the href's when the new dynamic content has been loaded into the DOM.

When the page loads, JQuery will look through the DOM for your $("#TestButton") and find nothing as at the time when this happens the dynamic content has yet to be injected.

There are a couple of ways of handling this... firstly you can delay the wire up of the click events with JQuery until the new content has been injected, or you can use the .live function of JQuery.

$("#TestButton").live('click', function (ev) {
        ev.preventDefault()

        alert('Test Button Clicked'); 
    });

Actually... it seems Live has been depreciated as of JQuery 1.7

$("#TestButton").on('click', function (ev) {
            ev.preventDefault()

            alert('Test Button Clicked'); 
        });

asp.net mvc - Accessing twitter bootstrap modal-body content with jque...

jquery asp.net-mvc twitter-bootstrap modal-dialog
Rectangle 27 9

When pjax loads the new content, the bootstrap handlers haven't been bound to all of the elements. With typical jQuery elements, you can use 'live' to have jQuery detect new content and apply the correct handlers. Sorry if this first part is stuff you already know.

$('a').click(function() { alert('here') }

If you dynamically load content containing another anchor element, the click handler won't be bound to it.

$('a').live('click', function() { alert('here') }

when the new content is loaded, jQuery will add the click handler because it's bound using live.

Back to bootstrap. For something like a popover, there is no equivalent 'live' method as far as I can tell. You can't change this:

$('a').popover()
$('a').live('popover')  # WON'T WORK

So if the anchor is loaded via pjax (or ajax or anything dynamic), any new anchors aren't bound as popovers.

The way around that is it to bind a pjax:end event so you can do stuff after the pjax content is inserted. In the popover example:

$(document)
  .on('pjax:end', function() { $('a').popover() })

Whenever pjax content is loaded it will run that function and apply the popover functionality to any anchor elements, including newly inserted ones. You could further isolate it via a selector to just the container with the new content so you don't reapply functionality to things that haven't changed.

jquery - Rails PJAX and Twitter Bootstrap Plugins Not Playing Nicely -...

jquery ruby-on-rails twitter-bootstrap pjax
Rectangle 27 1

Maybe you use an old jQuery version. I tried it with the jQuery CDN. You don't need twitter bootstrap for this and the script at the bottom of your script is not necessary to. Here's your correct code. Try it. I have tested it and it worked.

<!DOCTYPE html>
<html lang="en">
<head>

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">  
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
<title>TEST tabs</title>

</head>

<body>

<div class="container">

<!-------->
<div id="content">
    <ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
    <li class="active"><a href="#red" data-toggle="tab">Red</a></li>
    <li><a href="#orange" data-toggle="tab">Orange</a></li>
    <li><a href="#yellow" data-toggle="tab">Yellow</a></li>
    <li><a href="#green" data-toggle="tab">Green</a></li>
    <li><a href="#blue" data-toggle="tab">Blue</a></li>
</ul>
<div id="my-tab-content" class="tab-content">
    <div class="tab-pane active" id="red">
        <h1>Red</h1>
        <p>red red red red red red</p>
    </div>
    <div class="tab-pane" id="orange">
        <h1>Orange</h1>
        <p>orange orange orange orange orange</p>
    </div>
    <div class="tab-pane" id="yellow">
        <h1>Yellow</h1>
        <p>yellow yellow yellow yellow yellow</p>
    </div>
    <div class="tab-pane" id="green">
        <h1>Green</h1>
        <p>green green green green green</p>
    </div>
    <div class="tab-pane" id="blue">
        <h1>Blue</h1>
        <p>blue blue blue blue blue</p>
    </div>
    </div>
</div>


<script type="text/javascript">
$(document).ready(function () {
    $('#tabs').tab();
});
</script>    
</div> <!-- container -->



</body>
</html>

javascript - Bootstrap tab with content not working - Stack Overflow

javascript jquery html css twitter-bootstrap
Rectangle 27 4

Flavia Obreja and @Shane Courtrille, can you explain here "form submission from the modal" with bootstrap modal with an example without any plugin?

javascript - Using Bootstrap Modal window as PartialView - Stack Overf...

javascript asp.net-mvc twitter-bootstrap modal-dialog
Rectangle 27 4

Flavia Obreja and @Shane Courtrille, can you explain here "form submission from the modal" with bootstrap modal with an example without any plugin?

javascript - Using Bootstrap Modal window as PartialView - Stack Overf...

javascript asp.net-mvc twitter-bootstrap modal-dialog
Rectangle 27 1

<button type="button" class="btn btn-info btn-md" id="myBtn3">Static 
Modal</button>

<!-- Modal -->
<div class="modal fade" id="myModal3" role="dialog">
<div class="modal-dialog">
  <!-- Modal content-->
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal"></button>
      <h4 class="modal-title">Static Backdrop</h4>
    </div>
    <div class="modal-body">
      <p>You cannot click outside of this modal to close it.</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-
      dismiss="modal">Close</button>
    </div>
   </div>
  </div>
</div>
   <script>
    $("#myBtn3").click(function(){
     $("#myModal3").modal({backdrop: "static"});
    });
   });
  </script>

jquery - Disallow Twitter Bootstrap modal window from closing - Stack ...

jquery twitter-bootstrap modal-dialog mouseclick-event
Rectangle 27 0

<div class="modal fade" id="TCPage" data-backdrop="static">
  <div class="modal-dialog">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>
$('#TCPage').modal({
    show: true,
    backdrop: static,
    keyboard: false
});

if false backdrop removed and if static means onclick backdrop not to close.

jquery - Twitter bootstrap mvc4. stay with default black background co...

jquery asp.net-mvc-4 twitter-bootstrap
Rectangle 27 0

$("#myModal").on("show.bs.modal", function(e) {
    var link = $(e.relatedTarget);
    $(this).find(".modal-body").load(link.attr("href"));
});

jquery - Twitter bootstrap remote modal shows same content everytime -...

jquery jquery-plugins twitter-bootstrap modal-dialog
Rectangle 27 0

The jquery.validate documentation (as well as many answers here on StackOverflow) suggests that you use $.validator.setDefaults to assign the invalidHandler, but I couldn't get this to work in asp.net (it does work for focusInvalid however), probably due to us using the MS unobtrusive library. Instead I used this code in my jquery ready handler:

$(function() {
        $.validator.setDefaults({         
            focusInvalid: false
        });

        function scrollToError(error, validator) {
            var elem = $(validator.errorList[0].element);
            if (elem.length) {
                if (elem.is(':visible'))
                    return elem.offset().top - 16;
                elem = elem.prev($(".select2-container"));
                if (elem.length) {
                    return elem.offset().top - 16;
                }
            }
            return 0; // scroll to top if all else fails
        }

        $('form').bind('invalid-form.validate', function(error, validator) {
            // fix scrolling and validation for select2

            if (!validator.numberOfInvalids())
                return;

            $('html, body').animate({
                scrollTop: scrollToError(error, validator)
            }, 500);
        });
...

I set focusInvalid to false to disable and avoid conflict with the standard scroll and focus behavior.

The bind() call is used instead of the invalidHandler option and is the same as used by the validate plugin.

scrollToError() selects the first invalid element and returns the position to scroll to, either a normal visible element or a previous item with the 'select2-container' class (i.e a select2 element) or top of page if all else fails.

Standard behavior (showing validation errors etc) still works as before.

Hope this helps someone and if you have a better solution I would be very interested in knowing about it.

twitter bootstrap - select2 scroll to error not working with jquery va...

asp.net-mvc-4 twitter-bootstrap jquery-validate unobtrusive-validation jquery-select2
Rectangle 27 0

<div class="modal fade" id="searchKaryawan" tabindex="-1" role="dialog" aria-labelledby="SearchKaryawanLabel" aria-hidden="true"> <div class="modal-dialog">
<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="SearchKaryawanLabel">Cari Karyawan</h4>
  </div>
  <div class="modal-body">
    <input type="hidden" name="location">
    <input name="cariNama" type="text" class="form-control" onkeyup="if (this.value.length > 3) cariNikNama();" />
    <div class="links-area" id="links-area"></div>
  </div>
  <div class="modal-footer">
  </div>
</div> </div></div>
<script type="text/javascript">$('body').on('hidden.bs.modal', '.modal', function () {  $(".links-area").empty() }); </script>

links-area is area where i put the data and need to clear

jquery - Twitter bootstrap remote modal shows same content every time ...

jquery jquery-plugins twitter-bootstrap modal-dialog
Rectangle 27 0

The jquery.validate documentation (as well as many answers here on StackOverflow) suggests that you use $.validator.setDefaults to assign the invalidHandler, but I couldn't get this to work in asp.net (it does work for focusInvalid however), probably due to us using the MS unobtrusive library. Instead I used this code in my jquery ready handler:

$(function() {
        $.validator.setDefaults({         
            focusInvalid: false
        });

        function scrollToError(error, validator) {
            var elem = $(validator.errorList[0].element);
            if (elem.length) {
                if (elem.is(':visible'))
                    return elem.offset().top - 16;
                elem = elem.prev($(".select2-container"));
                if (elem.length) {
                    return elem.offset().top - 16;
                }
            }
            return 0; // scroll to top if all else fails
        }

        $('form').bind('invalid-form.validate', function(error, validator) {
            // fix scrolling and validation for select2

            if (!validator.numberOfInvalids())
                return;

            $('html, body').animate({
                scrollTop: scrollToError(error, validator)
            }, 500);
        });
...

I set focusInvalid to false to disable and avoid conflict with the standard scroll and focus behavior.

The bind() call is used instead of the invalidHandler option and is the same as used by the validate plugin.

scrollToError() selects the first invalid element and returns the position to scroll to, either a normal visible element or a previous item with the 'select2-container' class (i.e a select2 element) or top of page if all else fails.

Standard behavior (showing validation errors etc) still works as before.

Hope this helps someone and if you have a better solution I would be very interested in knowing about it.

twitter bootstrap - select2 scroll to error not working with jquery va...

asp.net-mvc-4 twitter-bootstrap jquery-validate unobtrusive-validation jquery-select2
Rectangle 27 0

<button type="button" class="btn btn-info btn-md" id="myBtn3">Static 
Modal</button>

<!-- Modal -->
<div class="modal fade" id="myModal3" role="dialog">
<div class="modal-dialog">
  <!-- Modal content-->
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal"></button>
      <h4 class="modal-title">Static Backdrop</h4>
    </div>
    <div class="modal-body">
      <p>You cannot click outside of this modal to close it.</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-
      dismiss="modal">Close</button>
    </div>
   </div>
  </div>
</div>
   <script>
    $("#myBtn3").click(function(){
     $("#myModal3").modal({backdrop: "static"});
    });
   });
  </script>

jquery - Disallow Twitter Bootstrap modal window from closing - Stack ...

jquery twitter-bootstrap modal-dialog mouseclick-event
Rectangle 27 0

You can manipulate the content of a remote content modal in Bootstrap 3 by using HTML 5 data attributes on the clicked element and listening for the modal show event.

<a data-toggle="modal" href="/remote.html" data-target="#myModal" data-merchant-name="Bob's House of Pancakes">Click me !</a>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Modal title</h4>

            </div>
            <div class="modal-body">
                <div class="te"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<script type="text/javascript">

// we can't use the show.bs.modal or loaded.bs.modal events
// because the remote modal content is not accessable in the DOM
// when those events trigger

// when the remote modal content is shown  
$('#myModal').on('shown.bs.modal', function (e) {

    // get a data attribute value from the clicked element
    var merchantName = $(e.relatedTarget).data('merchant-name');

    // and set the content of the shown remote modal
    $('#myModalLabel').text(merchantName);

});

// cleanup the content of the hidden remote modal because it is cached
$('#reservationModal').on('hide.bs.modal', function (e) {

    $(this).removeData('bs.modal');

});

</script>
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>

        </button>
         <h4 class="modal-title" id="myModalLabel">Modal title</h4>

    </div>
    <div class="modal-body">
        <!-- start slipsum code -->
        <p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
        <!-- please do not remove this line -->
        <div style="display:none;">
<a href="http://slipsum.com">lorem ipsum</a>
        </div>
        <!-- end slipsum code -->
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
    </div>
</div>

asp.net mvc - Accessing twitter bootstrap modal-body content with jque...

jquery asp.net-mvc twitter-bootstrap modal-dialog
Rectangle 27 0

When pjax loads the new content, the bootstrap handlers haven't been bound to all of the elements. With typical jQuery elements, you can use 'live' to have jQuery detect new content and apply the correct handlers. Sorry if this first part is stuff you already know.

$('a').click(function() { alert('here') }

If you dynamically load content containing another anchor element, the click handler won't be bound to it.

$('a').live('click', function() { alert('here') }

when the new content is loaded, jQuery will add the click handler because it's bound using live.

Back to bootstrap. For something like a popover, there is no equivalent 'live' method as far as I can tell. You can't change this:

$('a').popover()
$('a').live('popover')  # WON'T WORK

So if the anchor is loaded via pjax (or ajax or anything dynamic), any new anchors aren't bound as popovers.

The way around that is it to bind a pjax:end event so you can do stuff after the pjax content is inserted. In the popover example:

$(document)
  .on('pjax:end', function() { $('a').popover() })

Whenever pjax content is loaded it will run that function and apply the popover functionality to any anchor elements, including newly inserted ones. You could further isolate it via a selector to just the container with the new content so you don't reapply functionality to things that haven't changed.

jquery - Rails PJAX and Twitter Bootstrap Plugins Not Playing Nicely -...

jquery ruby-on-rails twitter-bootstrap pjax
Rectangle 27 0

Flavia Obreja and @Shane Courtrille, can you explain here "form submission from the modal" with bootstrap modal with an example without any plugin?

javascript - Using Bootstrap Modal window as PartialView - Stack Overf...

javascript asp.net-mvc twitter-bootstrap modal-dialog
Rectangle 27 0

You can manipulate the content of a remote content modal in Bootstrap 3 by using HTML 5 data attributes on the clicked element and listening for the modal show event.

<a data-toggle="modal" href="/remote.html" data-target="#myModal" data-merchant-name="Bob's House of Pancakes">Click me !</a>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Modal title</h4>

            </div>
            <div class="modal-body">
                <div class="te"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<script type="text/javascript">

// we can't use the show.bs.modal or loaded.bs.modal events
// because the remote modal content is not accessable in the DOM
// when those events trigger

// when the remote modal content is shown  
$('#myModal').on('shown.bs.modal', function (e) {

    // get a data attribute value from the clicked element
    var merchantName = $(e.relatedTarget).data('merchant-name');

    // and set the content of the shown remote modal
    $('#myModalLabel').text(merchantName);

});

// cleanup the content of the hidden remote modal because it is cached
$('#reservationModal').on('hide.bs.modal', function (e) {

    $(this).removeData('bs.modal');

});

</script>
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>

        </button>
         <h4 class="modal-title" id="myModalLabel">Modal title</h4>

    </div>
    <div class="modal-body">
        <!-- start slipsum code -->
        <p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
        <!-- please do not remove this line -->
        <div style="display:none;">
<a href="http://slipsum.com">lorem ipsum</a>
        </div>
        <!-- end slipsum code -->
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
    </div>
</div>

asp.net mvc - Accessing twitter bootstrap modal-body content with jque...

jquery asp.net-mvc twitter-bootstrap modal-dialog
Rectangle 27 0

$("#myModal").on("show.bs.modal", function(e) {
    var link = $(e.relatedTarget);
    $(this).find(".modal-body").load(link.attr("href"));
});

jquery - Twitter bootstrap remote modal shows same content every time ...

jquery jquery-plugins twitter-bootstrap modal-dialog
Rectangle 27 0

You can manipulate the content of a remote content modal in Bootstrap 3 by using HTML 5 data attributes on the clicked element and listening for the modal show event.

<a data-toggle="modal" href="/remote.html" data-target="#myModal" data-merchant-name="Bob's House of Pancakes">Click me !</a>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Modal title</h4>

            </div>
            <div class="modal-body">
                <div class="te"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<script type="text/javascript">

// we can't use the show.bs.modal or loaded.bs.modal events
// because the remote modal content is not accessable in the DOM
// when those events trigger

// when the remote modal content is shown  
$('#myModal').on('shown.bs.modal', function (e) {

    // get a data attribute value from the clicked element
    var merchantName = $(e.relatedTarget).data('merchant-name');

    // and set the content of the shown remote modal
    $('#myModalLabel').text(merchantName);

});

// cleanup the content of the hidden remote modal because it is cached
$('#reservationModal').on('hide.bs.modal', function (e) {

    $(this).removeData('bs.modal');

});

</script>
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>

        </button>
         <h4 class="modal-title" id="myModalLabel">Modal title</h4>

    </div>
    <div class="modal-body">
        <!-- start slipsum code -->
        <p>The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he who, in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy My brothers. And you will know My name is the Lord when I lay My vengeance upon thee.</p>
        <!-- please do not remove this line -->
        <div style="display:none;">
<a href="http://slipsum.com">lorem ipsum</a>
        </div>
        <!-- end slipsum code -->
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
    </div>
</div>

asp.net mvc - Accessing twitter bootstrap modal-body content with jque...

jquery asp.net-mvc twitter-bootstrap modal-dialog
Rectangle 27 0

You need to wire up the click events to the href's when the new dynamic content has been loaded into the DOM.

When the page loads, JQuery will look through the DOM for your $("#TestButton") and find nothing as at the time when this happens the dynamic content has yet to be injected.

There are a couple of ways of handling this... firstly you can delay the wire up of the click events with JQuery until the new content has been injected, or you can use the .live function of JQuery.

$("#TestButton").live('click', function (ev) {
        ev.preventDefault()

        alert('Test Button Clicked'); 
    });

Actually... it seems Live has been depreciated as of JQuery 1.7

$("#TestButton").on('click', function (ev) {
            ev.preventDefault()

            alert('Test Button Clicked'); 
        });

asp.net mvc - Accessing twitter bootstrap modal-body content with jque...

jquery asp.net-mvc twitter-bootstrap modal-dialog