misc: do not mark table with required field error before completion (#37449) #969
|
@ -1411,3 +1411,61 @@ def test_file_prefill_on_edit(pub, http_requests):
|
|||
# and persist after being saved again
|
||||
resp = resp.form.submit('submit').follow()
|
||||
assert '<span>test.txt</span>' in resp.text
|
||||
|
||||
|
||||
def test_form_page_prefill_and_table_field(pub):
|
||||
create_user(pub)
|
||||
formdef = create_formdef()
|
||||
formdef.data_class().wipe()
|
||||
formdef.fields = [
|
||||
fields.StringField(id='1', label='string', prefill={'type': 'string', 'value': 'HELLO WORLD'}),
|
||||
fields.TableField(id='2', label='table', rows=['A', 'B'], columns=['a', 'b', 'c']),
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
resp = get_app(pub).get('/test/')
|
||||
assert resp.forms[0]['f1'].value == 'HELLO WORLD'
|
||||
assert not resp.pyquery('.widget-with-error')
|
||||
|
||||
# check it also works on second page
|
||||
formdef.fields = [
|
||||
fields.PageField(id='0', label='page1'),
|
||||
fields.PageField(id='3', label='page2'),
|
||||
fields.StringField(id='1', label='string', prefill={'type': 'string', 'value': 'HELLO WORLD'}),
|
||||
fields.TableField(id='2', label='table', rows=['A', 'B'], columns=['a', 'b', 'c']),
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
resp = get_app(pub).get('/test/')
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.forms[0]['f1'].value == 'HELLO WORLD'
|
||||
assert not resp.pyquery('.widget-with-error')
|
||||
|
||||
|
||||
def test_form_page_prefill_and_tablerows_field(pub):
|
||||
create_user(pub)
|
||||
formdef = create_formdef()
|
||||
formdef.data_class().wipe()
|
||||
formdef.fields = [
|
||||
fields.StringField(id='1', label='string', prefill={'type': 'string', 'value': 'HELLO WORLD'}),
|
||||
fields.TableRowsField(id='2', label='table', columns=['a', 'b', 'c']),
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
resp = get_app(pub).get('/test/')
|
||||
assert resp.forms[0]['f1'].value == 'HELLO WORLD'
|
||||
assert not resp.pyquery('.widget-with-error')
|
||||
|
||||
# check it also works on second page
|
||||
formdef.fields = [
|
||||
fields.PageField(id='0', label='page1'),
|
||||
fields.PageField(id='3', label='page2'),
|
||||
fields.StringField(id='1', label='string', prefill={'type': 'string', 'value': 'HELLO WORLD'}),
|
||||
fields.TableRowsField(id='2', label='table', columns=['a', 'b', 'c']),
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
resp = get_app(pub).get('/test/')
|
||||
resp = resp.form.submit('submit')
|
||||
assert resp.forms[0]['f1'].value == 'HELLO WORLD'
|
||||
assert not resp.pyquery('.widget-with-error')
|
||||
|
|
|
@ -195,14 +195,18 @@ def test_table_list_rows_required():
|
|||
req.form = {}
|
||||
widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
|
||||
mock_form_submission(req, widget)
|
||||
widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
|
||||
assert widget.has_error()
|
||||
req.environ['REQUEST_METHOD'] = 'POST'
|
||||
try:
|
||||
widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
|
||||
assert widget.has_error()
|
||||
|
||||
req.form = {}
|
||||
widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
|
||||
mock_form_submission(req, widget, click='test$add_element')
|
||||
widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
|
||||
assert not widget.has_error()
|
||||
req.form = {}
|
||||
widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
|
||||
mock_form_submission(req, widget, click='test$add_element')
|
||||
widget = TableListRowsWidget('test', columns=['a', 'b', 'c'], required=True)
|
||||
assert not widget.has_error()
|
||||
finally:
|
||||
req.environ['REQUEST_METHOD'] = 'GET'
|
||||
|
||||
|
||||
def test_table_list_rows_set_many_values():
|
||||
|
|
|
@ -2761,7 +2761,7 @@ class TableWidget(CompositeWidget):
|
|||
CompositeWidget.parse(self, request=request)
|
||||
if request is None:
|
||||
request = get_request()
|
||||
if (request.form or request.get_method() == 'POST') and self.required:
|
||||
if request.get_method() == 'POST' and self.required:
|
||||
if not self.value:
|
||||
self.set_error(self.REQUIRED_ERROR)
|
||||
else:
|
||||
|
@ -3030,7 +3030,7 @@ class TableListRowsWidget(WidgetListAsTable):
|
|||
if request is None:
|
||||
request = get_request()
|
||||
add_element_pushed = self.get_widget('add_element').parse()
|
||||
if (request.form or request.get_method() == 'POST') and self.required:
|
||||
if request.get_method() == 'POST' and self.required:
|
||||
if not self.value and not add_element_pushed:
|
||||
self.set_error(self.REQUIRED_ERROR)
|
||||
for row in self.value or []:
|
||||
|
|
Loading…
Reference in New Issue