misc: use a textarea to enter prefill template for text fields (#49222) #854
|
@ -2267,6 +2267,37 @@ def test_form_edit_field_advanced(pub):
|
|||
assert 'Are you sure you want to prefill' not in resp.text
|
||||
|
||||
|
||||
def test_form_edit_prefill_text(pub):
|
||||
create_superuser(pub)
|
||||
create_role(pub)
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
formdef.fields = [
|
||||
fields.StringField(id='1', label='1st field'),
|
||||
fields.TextField(id='2', label='2nd field'),
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get(formdef.get_admin_url() + 'fields/1/')
|
||||
assert resp.pyquery('input[name="prefill$value_string"]')
|
||||
resp.forms[0]['prefill$type'] = 'String / Template'
|
||||
resp.forms[0]['prefill$value_string'] = 'xxx'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
formdef.refresh_from_storage()
|
||||
assert formdef.fields[0].prefill == {'type': 'string', 'locked': False, 'value': 'xxx'}
|
||||
|
||||
resp = app.get(formdef.get_admin_url() + 'fields/2/')
|
||||
assert resp.pyquery('textarea[name="prefill$value_string"]')
|
||||
resp.forms[0]['prefill$type'] = 'String / Template'
|
||||
resp.forms[0]['prefill$value_string'] = 'yyy'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
formdef.refresh_from_storage()
|
||||
assert formdef.fields[1].prefill == {'type': 'string', 'locked': False, 'value': 'yyy'}
|
||||
|
||||
|
||||
def test_form_edit_field_display(pub):
|
||||
create_superuser(pub)
|
||||
create_role(pub)
|
||||
|
|
|
@ -48,7 +48,7 @@ class SetValueError(Exception):
|
|||
|
||||
|
||||
class PrefillSelectionWidget(CompositeWidget):
|
||||
def __init__(self, name, value=None, field=None, **kwargs):
|
||||
def __init__(self, name, value=None, field=None, use_textarea=False, **kwargs):
|
||||
CompositeWidget.__init__(self, name, value, **kwargs)
|
||||
|
||||
if not value:
|
||||
|
@ -87,7 +87,7 @@ class PrefillSelectionWidget(CompositeWidget):
|
|||
|
||||
self.prefill_types = prefill_types = collections.OrderedDict(options)
|
||||
self.add(
|
||||
StringWidget,
|
||||
StringWidget if use_textarea is False else TextWidget,
|
||||
'value_string',
|
||||
size=80,
|
||||
value=value.get('value') if value.get('type') == 'string' else None,
|
||||
|
@ -830,6 +830,7 @@ class WidgetField(Field):
|
|||
display_locations = ['validation', 'summary']
|
||||
extra_attributes = []
|
||||
prefill = {}
|
||||
prefill_selection_widget_kwargs = {}
|
||||
|
||||
widget_class = None
|
||||
use_live_server_validation = False
|
||||
|
@ -948,6 +949,7 @@ class WidgetField(Field):
|
|||
value=self.prefill,
|
||||
advanced=True,
|
||||
field=self,
|
||||
**self.prefill_selection_widget_kwargs,
|
||||
)
|
||||
form.add(
|
||||
ConditionWidget,
|
||||
|
|
|
@ -45,6 +45,7 @@ class TextField(WidgetField):
|
|||
display_mode = 'plain'
|
||||
maxlength = None
|
||||
extra_attributes = ['cols', 'rows', 'maxlength']
|
||||
prefill_selection_widget_kwargs = {'use_textarea': True}
|
||||
|
||||
def migrate(self):
|
||||
changed = super().migrate()
|
||||
|
|
|
@ -1145,9 +1145,7 @@ div.ConditionWidget div.content select:focus {
|
|||
}
|
||||
|
||||
div.ValidationWidget div.content input[type=text],
|
||||
div.DataSourceSelectionWidget div.content input[type=text],
|
||||
div.PrefillSelectionWidget div.content select[data-dynamic-display-child-of],
|
||||
div.PrefillSelectionWidget div.content input[type=text] {
|
||||
div.DataSourceSelectionWidget div.content input[type=text] {
|
||||
max-width: 50%;
|
||||
margin: 0 1ex;
|
||||
}
|
||||
|
@ -1166,6 +1164,14 @@ div.PrefillSelectionWidget div.content input[type=submit] {
|
|||
}
|
||||
}
|
||||
|
||||
.PrefillSelectionWidget {
|
||||
.content {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
ul#field-filter,
|
||||
ul.columns-filter {
|
||||
list-style: none;
|
||||
|
|
Loading…
Reference in New Issue