forms: load geolocation javascript for geocoded text fields (#38792)
This commit is contained in:
parent
3a8d270098
commit
ec58f1e2bd
|
@ -4636,6 +4636,20 @@ def test_form_map_field_back_and_submit(pub):
|
|||
assert data.data == {'1': 'bla', '0': '1.234;-1.234'}
|
||||
|
||||
|
||||
def test_form_map_geolocation_text_field(pub):
|
||||
formdef = create_formdef()
|
||||
formdef.fields = [
|
||||
fields.MapField(id='0', label='map'),
|
||||
fields.TextField(id='1', label='street', required=True,
|
||||
prefill={'type': 'geolocation', 'value': 'road'}),
|
||||
]
|
||||
formdef.store()
|
||||
resp = get_app(pub).get('/test/')
|
||||
formdef.data_class().wipe()
|
||||
assert 'qommon.map.js' in resp.text
|
||||
assert 'qommon.geolocation.js' in resp.text
|
||||
|
||||
|
||||
def test_form_map_field_prefill_address(pub):
|
||||
formdef = create_formdef()
|
||||
formdef.fields = [
|
||||
|
|
|
@ -602,10 +602,16 @@ class DurationWidget(StringWidget):
|
|||
|
||||
|
||||
class TextWidget(quixote.form.TextWidget):
|
||||
prefill_attributes = None
|
||||
|
||||
def __init__(self, name, *args, **kwargs):
|
||||
self.validation_function = kwargs.pop('validation_function', None)
|
||||
super(TextWidget, self).__init__(name, *args, **kwargs)
|
||||
|
||||
def add_media(self):
|
||||
if self.prefill_attributes and 'geolocation' in self.prefill_attributes:
|
||||
get_response().add_javascript(['qommon.geolocation.js'])
|
||||
|
||||
def _parse(self, request, use_validation_function=True):
|
||||
quixote.form.TextWidget._parse(self, request)
|
||||
if self.value is not None:
|
||||
|
|
Loading…
Reference in New Issue