Skip to content

Commit

Permalink
Make file input layout and fix the image preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrienvh committed Feb 15, 2021
1 parent ea10faf commit 42956c1
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Backend/Core/Engine/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function addEditor($name, $value = null, $class = null, $classError = nul
public function addFile($name, $class = null, $classError = null): SpoonFormFile
{
$name = (string) $name;
$class = (string) ($class ?? 'custom-file-input');
$class = (string) ($class ?? 'form-control');
$classError = (string) ($classError ?? 'error form-control-danger is-invalid');

// add element
Expand All @@ -123,7 +123,7 @@ public function addFile($name, $class = null, $classError = null): SpoonFormFile
public function addImage($name, $class = null, $classError = null): FormImage
{
$name = (string) $name;
$class = (string) ($class ?? 'custom-file-input');
$class = (string) ($class ?? 'form-control');
$classError = (string) ($classError ?? 'error form-control-danger is-invalid');

// add element
Expand Down
8 changes: 4 additions & 4 deletions src/Backend/Core/Js/Components/Forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export class Forms {
}

fileUpload () {
$('.custom-file-input').on('change', (event) => {
$('.form-control[type="file"]').on('change', (event) => {
let file = ''
event = event.originalEvent

for (let i = 0; i < event.target.files.length; i++) {
file = event.target.files[i]
}

$(event.currentTarget).siblings('.custom-file-label').text(file.name)
$(event.currentTarget).siblings('.form-label').text(file.name)
})
}

Expand All @@ -51,8 +51,8 @@ export class Forms {
}

imagePreview () {
$('input[type=file]').on('change', () => {
const imageField = $(this).get(0)
$('input[type=file]').on('change', (event) => {
const imageField = event.target
// make sure we are uploading an image by checking the data attribute
if (imageField.getAttribute('data-fork-cms-role') === 'image-field' && imageField.files && imageField.files[0]) {
// get the image preview by matching the image-preview data-id to the ImageField id
Expand Down
4 changes: 2 additions & 2 deletions src/Backend/Core/Layout/Sass/_bootstrap-variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ $table-border-factor: .1;
$table-border-width: $border-width;
$table-border-color: $gray-200;

$table-striped-order: odd;
$table-striped-order: even;

$table-group-separator-color: $gray-200;

Expand Down Expand Up @@ -833,7 +833,7 @@ $form-range-thumb-disabled-bg: $gray-500;
$form-range-thumb-transition: background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;

$form-file-button-color: $input-color;
$form-file-button-bg: $input-group-addon-bg;
$form-file-button-bg: $gray-200;
$form-file-button-hover-bg: shade-color($form-file-button-bg, 5%);

$form-floating-height: add(3.5rem, $input-height-border);
Expand Down
7 changes: 7 additions & 0 deletions src/Backend/Core/Layout/Sass/components/_tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
width: 5%;
}

.table > tbody > tr > td,
.table > tbody > tr > th,
.table > tfoot > tr > td {
border: 0;
vertical-align: middle;
}

.table-align-top {

> tbody > tr > td,
Expand Down
2 changes: 1 addition & 1 deletion src/Backend/Core/Layout/Templates/FormLayout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% block form_widget_simple -%}
{% if type is not defined or type != 'hidden' %}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control' ~ (type|default('') == 'file' ? '-file custom-file-input' : ''))|trim}) -%}
{%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control')|trim}) -%}
{% endif %}
{%- if type is defined and (type == 'range' or type == 'color') %}
{# Attribute "required" is not supported #}
Expand Down
6 changes: 2 additions & 4 deletions src/Backend/Modules/Blog/Layout/Templates/Edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@
</label>
</div>
<div class="col-lg-9">
<div class="custom-file">
{% form_field image %}
<label class="custom-file-label" for="image">{{ 'lbl.ChooseFile'|trans|ucfirst }}</label>
</div>
<label class="form-label" for="image">{{ 'lbl.ChooseFile'|trans|ucfirst }}</label>
{% form_field image %}
{% form_field_error image %}
{% if item.image %}
<div class="form-check">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
{% endif %}
{% endif %}
{% if isAllowedAction('MediaFolderEdit') %}
{{ macro.buttonIcon('', 'pencil', 'lbl.EditMediaFolder'|trans|ucfirst, 'btn-default', {"data-toggle":"modal", "data-target":"#editMediaFolderDialog", "type":"button" } ) }}
{{ macro.buttonIcon('', 'pencil-alt', 'lbl.EditMediaFolder'|trans|ucfirst, 'btn-default', {"data-toggle":"modal", "data-target":"#editMediaFolderDialog", "type":"button" } ) }}
{% endif %}
</div>
</div>
Expand Down

0 comments on commit 42956c1

Please sign in to comment.