Skip to content

Commit

Permalink
Merge branch 'release/4.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Dec 3, 2020
2 parents 79c9155 + 14c571b commit 714b03f
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 27 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# v4.2.0
## 12/02/2020

1. [](#improved)
* Added support for arbitrary `attributes` on `form`, `textarea` and `checkbox` and `buttons`. [#447](https://github.com/getgrav/grav-plugin-form/issues/447) [#448](https://github.com/getgrav/grav-plugin-form/issues/448)
* Better support for array field key/value when either key or value are left empty
* Allow data-* form parameters to be used as <form> attributes. [#336](https://github.com/getgrav/grav-plugin-form/pull/336)
* Allow action param when including form partial [#410](https://github.com/getgrav/grav-plugin-form/pull/410)
* Also support validate min/max for textarea [#455](https://github.com/getgrav/grav-plugin-form/pull/455)
* Translate form labels also in text file [#444](https://github.com/getgrav/grav-plugin-form/pull/448)
1. [](#bugfix)
* Fixed KeepAlive issue where too large of a session value would fire the keep alive immediately
* Fixed stringable objects breaking the inputs
* Remove unused route variable from `file` field
* Fix condition for required attribute in toggle field [#451](https://github.com/getgrav/grav-plugin-form/pull/451)
* Fix form data template when select field is set to multiple [#452](https://github.com/getgrav/grav-plugin-form/pull/452)
* Fix has-errors for select and other fields [#454](https://github.com/getgrav/grav-plugin-form/pull/454)
* Fix #453 section title level [#459](https://github.com/getgrav/grav-plugin-form/pull/459)

# v4.1.2
## 10/07/2020

Expand Down
8 changes: 7 additions & 1 deletion app/fields/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ export default class ArrayField {
let escaped_name = !template.isValueOnly() ? keyElement.val() : this.getIndexFor(element);
escaped_name = escaped_name.toString().replace(/\[/g, '%5B').replace(/]/g, '%5D');
let name = `${template.getName()}[${escaped_name}]`;
valueElement.attr('name', !valueElement.val() ? template.getName() : name);

if (!template.isValueOnly() && (!keyElement.val() && !valueElement.val())) {
valueElement.attr('name', '');
} else {
// valueElement.attr('name', !valueElement.val() ? template.getName() : name);
valueElement.attr('name', name);
}

this.refreshNames(template);
}
Expand Down
4 changes: 3 additions & 1 deletion app/utils/keep-alive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import $ from 'jquery';
import {config} from 'grav-form';

const MAX_SAFE_DELAY = 2147483647;

$(document).ready(() => {
const keepAlive = $('[data-grav-keepalive]');

Expand All @@ -10,6 +12,6 @@ $(document).ready(() => {
$.ajax({
url: `${config.base_url_relative}/task${config.param_sep}keep-alive`
});
}, timeout);
}, Math.min(timeout, MAX_SAFE_DELAY));
}
});
4 changes: 2 additions & 2 deletions assets/form.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Form
slug: form
type: plugin
version: 4.1.2
version: 4.2.0
testing: false
description: Enables the forms handling
icon: check-square
Expand Down
13 changes: 12 additions & 1 deletion templates/forms/default/data.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@
{% elseif field.type == 'checkbox' %}
{{ (form.value(scope ~ field.name) == 1) ? "GRAV.YES"|t|e : "GRAV.NO"|t|e }}
{% elseif field.type == 'select' %}
{{ field.options[form.value(scope ~ field.name)]|e }}
{% set value = form.value(scope ~ field.name) %}
{% if value is iterable %}
<ul>
{% set use_keys = field.use is defined and field.use == 'keys' %}
{% for key, val in value %}
{% set index = (use_keys ? key : val) %}
<li>{{ field.options[index]|e }}</li>
{% endfor %}
</ul>
{% else %}
{{ field.options[value]|e }}
{% endif %}
{% else %}
{% set value = form.value(scope ~ field.name) %}
{% if value is iterable %}
Expand Down
2 changes: 1 addition & 1 deletion templates/forms/default/data.txt.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{%- if show_field %}
{%- set value = form.value(scope ~ (field.name ?? index)) -%}
{%- if value -%}
{{- field.label }}: {{ string(value is iterable ? value|json_encode : value|e) ~ "\r\n" }}
{{- field.label|t|e }}: {{ string(value is iterable ? value|json_encode : value|e) ~ "\r\n" }}
{%- endif -%}
{%- endif %}
{%- endif %}
Expand Down
28 changes: 27 additions & 1 deletion templates/forms/default/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% set form = grav.session.getFlashObject('form') %}
{% endif %}

{# Keep here for Backwards Compatibility #}
{% include 'partials/form-messages.html.twig' %}

{% set scope = scope ?: form.scope is defined ? form.scope : 'data.' %}
Expand All @@ -20,9 +21,10 @@
{% endif %}
{% endfor %}

{% set action = form.action ?: page.route ~ uri.params %}
{% set action = action ?? (form.action ?: page.route ~ uri.params) %}
{% set action = (action starts with 'http') or (action starts with '#') ? action : base_url ~ action %}
{% set action = action|trim('/', 'right') %}

{% if (action == base_url_relative) %}
{% set action = base_url_relative ~ '/' %}
{% endif %}
Expand Down Expand Up @@ -105,12 +107,27 @@
{% if form.id %}id="{{ form.id }}"{% endif %}
{% if form.novalidate %}novalidate{% endif %}
{% if form.keep_alive %}data-grav-keepalive="true"{% endif %}
{% if form.attributes is defined %}
{% for key,attribute in form.attributes %}
{% if attribute|of_type('array') %}
{{ attribute.name }}="{{ attribute.value|e('html_attr') }}"
{% else %}
{{ key }}="{{ attribute|e('html_attr') }}"
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}

{% block embed_form_classes -%}
class="{{ parent() }} {{ override_form_classes|trim }}"
{%- endblock %}

{% block embed_form_custom_attributes %}
{% for k, v in blueprints.form.attributes %}
{{ k }}="{{ v|e }}"
{% endfor %}
{% endblock %}

{% block embed_fields %}
{{ override_inner_markup_fields_start|raw }}
{{ override_inner_markup_fields|raw }}
Expand Down Expand Up @@ -143,6 +160,15 @@
{% if button.task %}name="task" value="{{ button.task }}"{% endif %}
{% endif %}
type="{{ button.type|default('submit') }}"
{% if button.attributes is defined %}
{% for key,attribute in button.attributes %}
{% if attribute|of_type('array') %}
{{ attribute.name }}="{{ attribute.value|e('html_attr') }}"
{% else %}
{{ key }}="{{ attribute|e('html_attr') }}"
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}

{% block embed_button_classes %}
Expand Down
9 changes: 9 additions & 0 deletions templates/forms/fields/checkbox/checkbox.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
{% if field.novalidate in ['on', 'true', 1] %}novalidate="novalidate"{% endif %}
{% if required %}required="required"{% endif %}
{% if field.tabindex %}tabindex="{{ field.tabindex }}"{% endif %}
{% if field.attributes is defined %}
{% for key,attribute in field.attributes %}
{% if attribute|of_type('array') %}
{{ attribute.name }}="{{ attribute.value|e('html_attr') }}"
{% else %}
{{ key }}="{{ attribute|e('html_attr') }}"
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}
/>
<label style="display:inline;" class="inline" for="{{ id|e }}">
Expand Down
Loading

0 comments on commit 714b03f

Please sign in to comment.