backoffice: dynamic custom view with an autocomplete field (#59679)
gitea-wip/wcs/pipeline/head Build started...
Details
gitea-wip/wcs/pipeline/head Build started...
Details
This commit is contained in:
parent
9ec9d31689
commit
5acf986c2c
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue