backoffice: dynamic custom view with an autocomplete field (#59679)
gitea-wip/wcs/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-12-14 16:23:38 +01:00
parent 9ec9d31689
commit 5acf986c2c
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 9 additions and 7 deletions

View File

@ -1189,19 +1189,18 @@ class FormPage(Directory):
options = [(x[0], x[1], x[0]) for x in options]
options.insert(0, (None, '', ''))
attrs = {'data-refresh-options': str(filter_field.contextual_id)}
if self.view and self.view.visibility == 'datasource':
options.append(('{}', _('custom value'), '{}'))
if filter_field_value and filter_field_value not in [x[0] for x in options]:
options.append((filter_field_value, filter_field_value, filter_field_value))
attrs['data-allow-template'] = 'true'
else:
current_filter = filters_dict.get('filter-%s-value' % filter_field.contextual_id)
options = [(current_filter, '', current_filter or '')]
options = [(filter_field_value, filter_field_value or '', filter_field_value or '')]
attrs = {'data-remote-options': str(filter_field.contextual_id)}
get_response().add_javascript(
['jquery.js', '../../i18n.js', 'qommon.forms.js', 'select2.js']
)
get_response().add_css_include('../js/select2/select2.css')
if self.view and self.view.visibility == 'datasource':
options.append(('{}', _('custom value'), '{}'))
if filter_field_value and filter_field_value not in [x[0] for x in options]:
options.append((filter_field_value, filter_field_value, filter_field_value))
attrs['data-allow-template'] = 'true'
r += SingleSelectWidget(
filter_field_key,

View File

@ -355,6 +355,9 @@ $(function() {
if ($(this).is('select[data-allow-template]') && $(this).val() == '{}') {
var replacement_input = $('<input></input>', {type: 'text', name: $(this).attr('name')});
$(this).parent().removeClass('SingleSelectWidget').addClass('StringWidget');
if ($(this).select2) {
$(this).select2('destroy');
}
$(this).replaceWith(replacement_input);
return;
}