0001-forms-use-standalone-js-to-give-focus-to-the-first-f.patch
wcs/qommon/form.py | ||
---|---|---|
361 | 361 |
if self.captcha: |
362 | 362 |
r += self.captcha.render() |
363 | 363 |
r += self._render_submit_widgets() |
364 |
if self.has_errors(): |
|
365 |
# if form has errors, focus and select the first widget on error |
|
366 |
r += htmltext("""<script type="text/javascript"> |
|
367 |
var all_obj = document.getElementsByTagName('DIV'); |
|
368 |
for (i=0; i<all_obj.length; i++) { |
|
369 |
if ( ( ' ' + all_obj[i].getAttribute("class") + ' ').toLowerCase().match( |
|
370 |
new RegExp ( '^.* widget-with-error .*$', 'g' ) ) ) { |
|
371 |
less_obj = all_obj[i].getElementsByTagName('INPUT'); |
|
372 |
for (j=0; j<less_obj.length; j++) { |
|
373 |
less_obj[j].select(); |
|
374 |
less_obj[j].focus(); |
|
375 |
break; |
|
376 |
} |
|
377 |
break; |
|
378 |
} |
|
379 |
} |
|
380 |
</script>""") |
|
381 | 364 |
return r.getvalue() |
382 | 365 | |
383 | 366 |
def _render_prefill_widgets(self): |
wcs/qommon/static/js/qommon.forms.js | ||
---|---|---|
31 | 31 |
$('#tracking-code button').click(function() { |
32 | 32 |
$('input[name=savedraft]').click(); |
33 | 33 |
}); |
34 |
if ($('.widget-with-error').length) { |
|
35 |
var first_field_with_error = $($('.widget-with-error')[0]).find('input,textarea,select'); |
|
36 |
if (first_field_with_error.length) { |
|
37 |
$(first_field_with_error)[0].focus(); |
|
38 |
} |
|
39 |
} |
|
34 | 40 |
}); |
35 |
- |