From c820a0f2f7c589bc231fb7290ecc217384489d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 30 May 2016 20:21:30 +0200 Subject: [PATCH] forms: use standalone js to give focus to the first field with errors (#11137) --- wcs/qommon/form.py | 17 ----------------- wcs/qommon/static/js/qommon.forms.js | 6 ++++++ 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index 33a36f2..a7ba2c9 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -361,23 +361,6 @@ class Form(QuixoteForm): if self.captcha: r += self.captcha.render() r += self._render_submit_widgets() - if self.has_errors(): - # if form has errors, focus and select the first widget on error - r += htmltext("""""") return r.getvalue() def _render_prefill_widgets(self): diff --git a/wcs/qommon/static/js/qommon.forms.js b/wcs/qommon/static/js/qommon.forms.js index 67192bb..e0a161f 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -31,4 +31,10 @@ $(function() { $('#tracking-code button').click(function() { $('input[name=savedraft]').click(); }); + if ($('.widget-with-error').length) { + var first_field_with_error = $($('.widget-with-error')[0]).find('input,textarea,select'); + if (first_field_with_error.length) { + $(first_field_with_error)[0].focus(); + } + } }); -- 2.8.1