From d5f6f02b140b622fe95467e2aa585109c0453f8f Mon Sep 17 00:00:00 2001 From: Sebastian Castro <sebastian.castro@protonmail.com> Date: Tue, 4 May 2021 18:08:59 +0200 Subject: [PATCH] form-builder: adds checked_value option for checkbox field --- assets/js/element-form/initialisation.js | 6 ++++++ config/parameters.yaml | 2 +- .../admin/core_custom/custom-fields/form-builder.html.twig | 1 + templates/element-form/form-partials/checkbox.html.twig | 1 + translations/admin+intl-icu.fr.yaml | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/js/element-form/initialisation.js b/assets/js/element-form/initialisation.js index da8f8cdf0..bceefe1bf 100755 --- a/assets/js/element-form/initialisation.js +++ b/assets/js/element-form/initialisation.js @@ -41,6 +41,12 @@ jQuery(document).ready(function() initializeToHtml() + // Checkboxes, use custom checked value + $('input[type=checkbox]').change(function() { + if ($(this).val() == 'on' && $(this).data('checked-value') != 'on') + $(this).val($(this).data('checked-value')) + }) + // TIMEPICKERS $('.timepicker').each(function(e) { var start_time; diff --git a/config/parameters.yaml b/config/parameters.yaml index 66cda5dbb..4d3659b99 100755 --- a/config/parameters.yaml +++ b/config/parameters.yaml @@ -1,7 +1,7 @@ # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: - app.version: 3.2.7 + app.version: 3.2.8 locale: fr router.request_context.host: '%env(string:BASE_URL)%' from_email: "%env(FROM_EMAIL)%" diff --git a/templates/admin/core_custom/custom-fields/form-builder.html.twig b/templates/admin/core_custom/custom-fields/form-builder.html.twig index 35bc5f2e9..eec636c48 100755 --- a/templates/admin/core_custom/custom-fields/form-builder.html.twig +++ b/templates/admin/core_custom/custom-fields/form-builder.html.twig @@ -109,6 +109,7 @@ label: t('js.form_builder.defaultvalue'), options: { 'no': t('js.form_builder.options.no'), 'yes': t('js.form_builder.options.yes') } }, + checked_value: { label: t("js.form_builder.checked_value"), value: "on"}, errorMsg: errorMsgAttrs }, email: { diff --git a/templates/element-form/form-partials/checkbox.html.twig b/templates/element-form/form-partials/checkbox.html.twig index 654287c11..1d09fa90b 100755 --- a/templates/element-form/form-partials/checkbox.html.twig +++ b/templates/element-form/form-partials/checkbox.html.twig @@ -1,6 +1,7 @@ <div class="checkbox-container"> <input type="checkbox" name="data[{{ field.name }}]" id="{{ field.name }}" {% if field.required|default(false) %}class="required"{% endif %} + data-checked-value="{{ field.checked_value }}" {% if elementValue or not elementValue and field.defaultvalue == "yes" %}checked="checked"{% endif %}/> <label for="{{ field.name }}" class="to-html">{{ field.label|raw }}</label> </div> \ No newline at end of file diff --git a/translations/admin+intl-icu.fr.yaml b/translations/admin+intl-icu.fr.yaml index d826dc801..ede704f16 100755 --- a/translations/admin+intl-icu.fr.yaml +++ b/translations/admin+intl-icu.fr.yaml @@ -1280,6 +1280,7 @@ js: # Below keys are available to javascript icon_placeholder: "Choisissez une icône" remove_icon: "Supprimer" copy_icon: "Dupliquer" + checked_value: Valeur du champ si coché edit_icon: "Editer/Masquer" label: "Libellé" errorMsg: "Msg. Erreur" -- GitLab