snipt

Ctrl+h for KB shortcuts

Text only

jQuery : Event on a checkbox called twice

1
2
3
4
5
That's because when you bind a click event on a label with a "for" attribute it triggers the event twice :
 - One on the label
 - One on the checkbox
 
The selector should be bound to the checkbox, not the label to be triggered only once
https://snipt.net/embed/ee33427ba4f6a5dba3e0d10d073175b7/
/raw/ee33427ba4f6a5dba3e0d10d073175b7/
ee33427ba4f6a5dba3e0d10d073175b7
text
Text only
6
2019-06-14T14:03:56
True
False
True
Oct 29, 2012 at 04:37 AM
/api/public/snipt/46589/
jquery-event-on-a-checkbox-called-twice
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>That&#39;s because when you bind a click event on a label with a &quot;for&quot; attribute it triggers the event twice : </span><span id="L-2"><a name="L-2"></a> - One on the label </span><span id="L-3"><a name="L-3"></a> - One on the checkbox </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a>The selector should be bound to the checkbox, not the label to be triggered only once </span></pre></div> </td></tr></table>
event, jQuery

JavaScript

DataTable : Custom row number

1
2
3
4
5
6
$(document).ready( function() {
  $('#example').dataTable( {
    "aLengthMenu": [[25, 50, -1], [25, 50, "All"]],
    "iDisplayLength": 25
  });
});
https://snipt.net/embed/61d84d22f817d2d20cb822cbd11235db/
/raw/61d84d22f817d2d20cb822cbd11235db/
61d84d22f817d2d20cb822cbd11235db
js
JavaScript
6
2016-12-18T05:39:08
True
False
True
Oct 29, 2012 at 04:28 AM
/api/public/snipt/46646/
datatable-custom-row-number
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">ready</span><span class="p">(</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#example&#39;</span><span class="p">).</span><span class="nx">dataTable</span><span class="p">(</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="s2">&quot;aLengthMenu&quot;</span><span class="o">:</span> <span class="p">[[</span><span class="mi">25</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">25</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="s2">&quot;All&quot;</span><span class="p">]],</span> </span><span id="L-4"><a name="L-4"></a> <span class="s2">&quot;iDisplayLength&quot;</span><span class="o">:</span> <span class="mi">25</span> </span><span id="L-5"><a name="L-5"></a> <span class="p">});</span> </span><span id="L-6"><a name="L-6"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
DataTable

Text only

Drupal 7 : Meta tags don't display (With Panels)

If your meta tags are not showing on your page, you may check if the option "No extra" isn't checked on your variant settings page.
Variant / Content / Click on your block / Settings / No extra
https://snipt.net/embed/190b422fd1cc637754cbfc80a628fc2d/
/raw/190b422fd1cc637754cbfc80a628fc2d/
190b422fd1cc637754cbfc80a628fc2d
text
Text only
2
2016-12-20T05:34:22
True
False
True
Oct 26, 2012 at 12:26 PM
/api/public/snipt/49112/
drupal-7-meta-tags-dont-display
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>If your meta tags are not showing on your page, you may check if the option &quot;No extra&quot; isn&#39;t checked on your variant settings page. </span><span id="L-2"><a name="L-2"></a>Variant / Content / Click on your block / Settings / No extra </span></pre></div> </td></tr></table>
"drupal 7", metatags, panel

JavaScript

jQuery : Bind an event on an ajax reloaded DOM

1
2
3
4
5
6
7
$('body').on("click", "#select-status a", function(e){
    e.preventDefault();
    // My actions
});

// You have to bind the event on a part of the DOM which is not reloaded by the ajax call.
// Then you can write your real selector in the parameters
https://snipt.net/embed/94314a16cbd8aecb23f43f01a6165516/
/raw/94314a16cbd8aecb23f43f01a6165516/
94314a16cbd8aecb23f43f01a6165516
js
JavaScript
7
2016-12-20T06:12:51
True
False
True
Oct 15, 2012 at 06:07 AM
/api/public/snipt/48576/
jquery-bind-an-event-on-an-ajax-reloaded-dom
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;body&#39;</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s2">&quot;click&quot;</span><span class="p">,</span> <span class="s2">&quot;#select-status a&quot;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">){</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">e</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span> </span><span id="L-3"><a name="L-3"></a> <span class="c1">// My actions</span> </span><span id="L-4"><a name="L-4"></a><span class="p">});</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c1">// You have to bind the event on a part of the DOM which is not reloaded by the ajax call.</span> </span><span id="L-7"><a name="L-7"></a><span class="c1">// Then you can write your real selector in the parameters</span> </span></pre></div> </td></tr></table>
ajax, bind, jquery, live, on

Text only

Symfony 1.x : Add Error 500 page

1
2
3
4
5
6
7
Add the file error.html.php in /config/error

To test it, add this in your action:
throw new sfException('Testing the 500 error');

To see it don't forget to set your $debug at false in your front controller:
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', false);
https://snipt.net/embed/8c3aa50151a5ace72a2f03c71c332a23/
/raw/8c3aa50151a5ace72a2f03c71c332a23/
8c3aa50151a5ace72a2f03c71c332a23
text
Text only
7
2016-12-19T09:28:25
True
False
True
Oct 12, 2012 at 09:58 AM
/api/public/snipt/47349/
symfony-1x-error-500-prod
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>Add the file error.html.php in /config/error </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>To test it, add this in your action: </span><span id="L-4"><a name="L-4"></a>throw new sfException(&#39;Testing the 500 error&#39;); </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a>To see it don&#39;t forget to set your $debug at false in your front controller: </span><span id="L-7"><a name="L-7"></a>$configuration = ProjectConfiguration::getApplicationConfiguration(&#39;frontend&#39;, &#39;dev&#39;, false); </span></pre></div> </td></tr></table>
"error 500", Symfony