Permalink
Browse files

netteForms: support for toggling by CSS selector, not only id (#210)

this is useful eg. for controls manually rendered as table cells `<td>` which have only `<tr>` valid parent .. if there are multiple cells within table row toggling via `id` is not feasible (it would toggle all the cells in that row).
  • Loading branch information...
Ciki authored and dg committed Feb 11, 2019
1 parent 11e21e5 commit f915992dc53d26d52bec84f80761e0ee40878414
Showing with 7 additions and 4 deletions.
  1. +7 −4 src/assets/netteForms.js
@@ -654,10 +654,13 @@
/**
* Displays or hides HTML element.
*/
Nette.toggle = function(id, visible, srcElement) { // eslint-disable-line no-unused-vars
var elem = document.getElementById(id);
if (elem) {
elem.style.display = visible ? '' : 'none';
Nette.toggle = function(selector, visible, srcElement) { // eslint-disable-line no-unused-vars
if (/^\w+$/.test(selector)) { // id
selector = '#' + selector;
}
var elems = document.querySelectorAll(selector);
for (var i = 0; i < elems.length; i++) {
elems[i].style.display = visible ? '' : 'none';
}
};

0 comments on commit f915992

Please sign in to comment.