backoffice: ignore filter dates with leading 0 (#56205)
This commit is contained in:
parent
db05d872e9
commit
70fc9d0c21
|
@ -865,6 +865,11 @@ def test_backoffice_filter(pub):
|
|||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count('<td>baz</td>') == 8
|
||||
|
||||
# and dates being typed in are properly ignored
|
||||
resp.forms['listing-settings']['filter-start-value'] = '0020-02-01'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert resp.text.count('<td>baz</td>') == 8
|
||||
|
||||
# check it's also ok for end filter
|
||||
resp.forms['listing-settings']['filter-end'].checked = True
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
|
|
|
@ -251,6 +251,10 @@ def date_format():
|
|||
|
||||
|
||||
def get_as_datetime(s):
|
||||
if s and re.match(r'^0\d\d\d-\d\d-\d\d$', s):
|
||||
# iso date with year starting with 0, it's likely currently being
|
||||
# typed in an HTML5 date input widget, consider it invalid.
|
||||
raise ValueError('invalid date, leading 0')
|
||||
formats = [datetime_format(), date_format()] # prefer current locale
|
||||
for value in DATETIME_FORMATS.values():
|
||||
formats.extend(value)
|
||||
|
|
|
@ -347,6 +347,11 @@ $(function() {
|
|||
|
||||
/* automatically refresh onfilter change */
|
||||
$('form#listing-settings input[type=date], form#listing-settings input[type=text], form#listing-settings select').change(function() {
|
||||
if (this.type == 'date' && $(this).val() && $(this).val()[0] == '0') {
|
||||
// input date with year starting with 0, it's currently being typed in,
|
||||
// wait for the year to be complete before acting on it.
|
||||
return;
|
||||
}
|
||||
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');
|
||||
|
|
Loading…
Reference in New Issue