Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Give alert if form checkbox array is empty Date: Fri, 22 Jan 2016 00:07:14 +0100 Organization: PointedEars Software (PES) Lines: 92 Message-ID: <1667727.3LLY7Eaobt@PointedEars.de> References: <5888602.Nj0jmESFCg@PointedEars.de> <405a9$569fab1d$11450e97$16733@nntpswitch.blueworldhosting.com> <3964788.uURLdzOTfL@PointedEars.de> <19572$56a08e96$520da86c$20767@nntpswitch.blueworldhosting.com> <2757422.ibQTPl4PXH@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1453417637 5140 eJwFwQkBwDAIA0BLZSOByuH1L6F3+CksU4KKxbI6FSbRlbNfhdrskXH4wW26R2ShJ3BP6Tw5MhIj (21 Jan 2016 23:07:17 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 21 Jan 2016 23:07:17 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNy8kBwCAIBMCWwuEi5awC/ZcQ5z/LILjhWPA1a7KDWeGKJOuUgF17FPta0dSPsboZ0kWXo29YxjTGv7d+fuMWiw== Cancel-Lock: sha1:FiDnQV+OKtKu9Q10x4YjviTmK5g= X-NNTP-Posting-Host: eJwFwYEBwDAEBMCV8sRjHA32H6F3pgSfXxqvrW2kS4XmgC3WFNEKIgrE7GvM5/MC2ycphz8LKBCq Xref: csiph.com comp.lang.javascript:29398 Cezary Tomczyk wrote: > On 21/01/2016 09:52, Thomas 'PointedEars' Lahn wrote: >> […] The *support* of document.querySelector() does _not_ imply support$ >> of certain *selectors* *because* certain selectors were not yet >> specified/supported when document.querySelector() was introduced. For >> example, the “:checked” pseudo class was standardized with CSS3 Selectors >> in 2011 [1]; document.querySelector() was standardized with Selectors API >> Level 1 in2013 [2]. >> >> [1] >> [2] > > Got it. It was a bad example, though, because specification-wise “:checked” *predates* querySelector() (qS) and querySelectorAll() (qSA). On the other hand it shows the chronological disparity between the support of either feature. That is, “:checked” *might* be safe with qS() and qSA() – and a comparison on suggests it is [1]¹ – because it became a standard before d.qS(), but you can think of more recently introduced/supported selectors to which this does not apply because of that. where the “Level” is “4” only, are prime candidates. > Can you recommend some reliable way of test if specified selector is > supported or not? Perhaps. (Wrong question ;-)) (But: Good question, in this case.) There might be a reliable way. It is specified both in Selectors API Level 1 (which refers to CSS Selectors Level 3) and DOM Level 4 (which refers to CSS Selectors Level 4 [WD/ED]) that for an “*invalid*” selector a DOMException with the “code” attribute set to DOMException::SYNTAX_ERR (12) should be thrown by qS() and qSA(): This is implemented so in Blink 537.26 (tested in Chromium 46.0.2490.71 on Debian GNU/Linux) and Gecko 38.0 (Iceweasel 38.1.0), i.e. a DOMException is thrown whose “code” property has the value 12. Blink: | > try { document.querySelector(":blub") } catch (e) { console.log(e, | > e.code) } | DOMException: Failed to execute 'querySelector' on 'Document': ':blub' is | not a valid selector.(…) 12 Gecko: | < try { document.querySelector(":blub") } catch (e) { e } | > […] DOMException [SyntaxError: "An invalid or illegal string was | > specified" | code: 12 | nsresult: 0x8053000c | location: debugger eval code:1] Therefore, the following works there: try { document.querySelector(":blub"); } catch (e) { if (e instanceof DOMException && e.code === 12) // ² { /* handling for invalid/unsupported selector */ } } This can be confirmed for specified but unsupported selectors in that Gecko version with ":read-write" and in that Blink version with ":drop(…)". ________ ¹ Something can be learned here: In a compatibility matrix, it can be useful to provide functionality to compare the support for *several* features in one view. caniuse.com does not provide such yet, so I had to open several tabs and switch between them. ² They should have standardized Mozilla’s “… catch (e if …) { … }” so that you can have “… catch (e if e instanceof DOMException) { … }” as a shortcut everywhere. [1] -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.