Projet

Général

Profil

0001-forms-scroll-newly-added-block-into-view-46111.patch

Frédéric Péters, 02 février 2021 13:57

Télécharger (3,31 ko)

Voir les différences:

Subject: [PATCH] forms: scroll newly added block into view (#46111)

 tests/form_pages/test_block.py                       | 3 +++
 wcs/blocks.py                                        | 4 ++++
 wcs/qommon/static/js/qommon.forms.js                 | 5 +++++
 wcs/qommon/templates/qommon/forms/widgets/block.html | 2 +-
 4 files changed, 13 insertions(+), 1 deletion(-)
tests/form_pages/test_block.py
726 726
    resp = app.get(formdef.get_url())
727 727
    assert resp.text.count('>Test<') == 1
728 728
    assert resp.text.count('>hintblock<') == 1
729
    assert 'wcs-block-add-clicked' not in resp
729 730
    assert 'Add another' in resp
730 731
    assert resp.html.find('div', {'class': 'list-add'})
731 732
    resp = resp.form.submit('f1$add_element')
732 733
    assert resp.text.count('>Test<') == 2
733 734
    assert resp.text.count('>hintblock<') == 1
735
    assert 'wcs-block-add-clicked' in resp
734 736
    resp = resp.form.submit('f1$add_element')
735 737
    assert resp.text.count('>Test<') == 3
736 738
    assert resp.text.count('>hintblock<') == 1
......
752 754

  
753 755
    resp = resp.form.submit('previous')  # -> 2nd page
754 756
    resp = resp.form.submit('previous')  # -> 1st page
757
    assert 'wcs-block-add-clicked' not in resp
755 758
    assert 'readonly' not in resp.form['f1$element0$f123'].attrs
756 759
    assert resp.form['f1$element0$f123'].value == 'foo'
757 760

  
wcs/blocks.py
345 345
            attrs['aria-describedby'] = 'form_hint_%s' % self.name
346 346
        title_tag = htmltag('h4', **attrs)
347 347
        return title_tag + htmltext('%s</h4>') % title
348

  
349
    def had_add_clicked(self):
350
        add_widget = self.get_widget('add_element')
351
        return get_request().form.get(add_widget.name) if add_widget else False
wcs/qommon/static/js/qommon.forms.js
487 487
    }
488 488
    return false;
489 489
  });
490

  
491
  const $added_sub_widget = $('.wcs-block-add-clicked').find('.BlockSubWidget').last();
492
  if ($added_sub_widget.length) {
493
    $added_sub_widget[0].scrollIntoView();
494
  }
490 495
});
wcs/qommon/templates/qommon/forms/widgets/block.html
1 1
{% extends "qommon/forms/widget.html" %}
2 2

  
3
{% block widget-css-classes %}{{ block.super }} {% if widget.remove_button %}wcs-block-with-remove-button{% endif %}{% endblock %}
3
{% block widget-css-classes %}{{ block.super }} {% if widget.had_add_clicked %}wcs-block-add-clicked{% endif %} {% if widget.remove_button %}wcs-block-with-remove-button{% endif %}{% endblock %}
4
-