Skip to content

Commit 8879baf

Browse files
bechiratierant
authored andcommitted
Fix & integrate flatpickr
1 parent 779ed96 commit 8879baf

File tree

7 files changed

+28
-12
lines changed

7 files changed

+28
-12
lines changed

assets/admin.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import './styles/admin.scss';
22
import 'typeahead.js';
33
import Bloodhound from "bloodhound-js";
44
import 'bootstrap-tagsinput';
5+
import 'flatpickr';
6+
import 'flatpickr/dist/flatpickr.css';
7+
import moment from 'moment';
58

69
$(function() {
710
// Bootstrap-tagsinput initialization
@@ -24,6 +27,18 @@ $(function() {
2427
}
2528
});
2629
}
30+
31+
$('[data-toggle="datetimepicker"]').flatpickr({
32+
enableTime: true,
33+
dateFormat: $('#post_publishedAt').data('date-format'),
34+
allowInput: true,
35+
parseDate: (datestr, format) => {
36+
return moment(datestr, format, true).toDate();
37+
},
38+
formatDate: (date, format, locale) => {
39+
return moment(date).format(format);
40+
}
41+
});
2742
});
2843

2944
// Handling the modal confirmation message.

assets/styles/bootstrap-tagsinput.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
flex: 1 1;
9191
width: 1%;
9292
height: 45px;
93-
padding: 00.125rem 0 0 0;
93+
padding: .125rem 0 0 0;
9494
font-size: 15px;
9595
line-height: 1.42857143;
9696
color: #2c3e50;

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
"bootstrap-tagsinput": "^0.7.1",
1313
"bootswatch": "^4.5.3",
1414
"core-js": "^3.23.0",
15+
"flatpickr": "^4.6.9",
1516
"highlight.js": "^11.5.1",
1617
"imports-loader": "^0.8.0",
1718
"jquery": "^3.5.1",
1819
"lato-font": "^3.0.0",
19-
"moment": "^2.10",
20+
"moment": "^2.29.1",
2021
"moment-timezone": "^0.5.40",
22+
"node-sass": "^4.9.3",
23+
"popper.js": "^1.16.1",
2124
"regenerator-runtime": "^0.13.2",
2225
"sass": "^1.53.0",
2326
"sass-loader": "^13.2",

templates/base.html.twig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
common elements and decorates all the other templates.
44
See https://symfony.com/doc/current/templates.html#template-inheritance-and-layouts
55
#}
6-
7-
{% set _route = app.request.get('_route') %}
8-
96
<!DOCTYPE html>
107
<html lang="{{ app.request.locale }}">
118
<head>
@@ -31,6 +28,7 @@
3128
<body id="{% block body_id %}{% endblock %}">
3229

3330
{% block header %}
31+
{% set _route = app.request.get('_route') %}
3432
<header>
3533
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-primary">
3634
<div class="container">

templates/form/fields.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<div class="input-group date" data-toggle="datetimepicker">
1212
{{ block('datetime_widget') }}
1313
<div class="input-group-append">
14-
<button class="btn btn-outline-secondary">
14+
<span class="btn btn-outline-secondary">
1515
<span class="fa fa-calendar" aria-hidden="true"></span>
16-
</button>
16+
</span>
1717
</div>
1818
</div>
1919
{% endblock %}

templates/form/layout.html.twig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
{# Errors #}
44

5-
{% block form_errors -%}
5+
{# {% block form_errors -%}
66
{% if errors|length > 0 -%}
77
{% if form is not rootform %}<span class="help-block">{% else %}<div class="alert alert-danger">{% endif %}
88
<ul class="list-unstyled">
99
{%- for error in errors -%}
10-
{# use font-awesome icon library #}
10+
{# use font-awesome icon library # }
1111
<li><span class="fa fa-exclamation-triangle"></span> {{ error.message }}</li>
1212
{%- endfor -%}
1313
</ul>
1414
{% if form is not rootform %}</span>{% else %}</div>{% endif %}
1515
{%- endif %}
16-
{%- endblock form_errors %}
16+
{%- endblock form_errors %} #}

tests/Controller/Admin/BlogControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public function testAdminNewDuplicatedPost(): void
135135
// post titles must be unique, so trying to create the same post twice should result in an error
136136
$this->client->submit($form);
137137

138-
$this->assertSelectorTextSame('form .form-group.has-error label', 'Title');
139-
$this->assertSelectorTextContains('form .form-group.has-error .help-block', 'This title was already used in another blog post, but they must be unique.');
138+
$this->assertSelectorTextContains('form .invalid-feedback .form-error-message', 'This title was already used in another blog post, but they must be unique.');
139+
$this->assertSelectorExists('form #post_title.is-invalid');
140140
}
141141

142142
public function testAdminShowPost(): void

0 commit comments

Comments
 (0)