Closed mccarthysean closed 3 years ago
Seems it's related to this issue and the data-template
that needs to be removed.
Flask-Admin doesn't remove the data-template
for this date field since it's just given a data-role='x-editable'
instead lf x-editable-combodate
.
There are at least two ways of fixing this (in the JavaScript "forms.js" or in the XEditableWidget class's get_kwargs()
method). I chose to fix it in the get_kwargs()
method as follows:
class XEditableWidget(object):
# ...
def get_kwargs(self, field, kwargs):
"""
Return extra kwargs based on the field type.
"""
if field.type == 'StringField':
kwargs['data-type'] = 'text'
# ...
elif field.type == 'DateField':
kwargs['data-type'] = 'combodate'
kwargs['data-format'] = 'YYYY-MM-DD'
# Remove the following so JavaScript doesn't have to do it?
# kwargs['data-template'] = 'YYYY-MM-DD'
# Use the following so it adjusts the template
kwargs['data-role'] = 'x-editable-combodate'
Here's what happens in the "form.js" file on page-load (i.e. where the data-template
attribute is removed, in the latest Flask-Admin "master" branch):
case 'x-editable':
// No removal of the "data-template" attribute
$el.editable({
params: overrideXeditableParams,
combodate: {
// prevent minutes from showing in 5 minute increments
minuteStep: 1,
maxYear: 2030,
}
});
return true;
case 'x-editable-combodate':
// Fixes bootstrap4 issue where data-template breaks bs4 popover.
// https://github.com/flask-admin/flask-admin/issues/2022
let template = $el.data('template');
$el.removeAttr('data-template');
$el.editable({
params: overrideXeditableParams,
template: template,
combodate: {
// prevent minutes from showing in 5 minute increments
minuteStep: 1,
maxYear: 2030,
}
});
return true;
The resulting popover is a tiny bit ugly now, for some reason, but functionally it works at least!
@mccarthysean This can be closed as #2146 has been merged into master
I think I've found an error/bug in Flask-Admin's X-editable dates, but only in Bootstrap 4.
Here's a StackOverflow question that's identical to below.
Notice in the below code,
template_mode='bootstrap3'
works fine, buttemplate_mode='bootstrap4'
causes the error.Code to reproduce the error:
Here's what the Flask-Admin view looks like with Bootstrap 4, before the error:
Here's what the error looks like in the JavaScript console, when I click on the "editable" date field:
Here's what it looks like using the template_mode='bootstrap3' (i.e. what it's supposed to do):