Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI authored Sep 22, 2023
2 parents 395d2a2 + 2ae0c57 commit 85b19db
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [4.27.1](https://github.com/sonata-project/SonataAdminBundle/compare/4.27.0...4.27.1) - 2023-09-21
### Added
- [[#8105](https://github.com/sonata-project/SonataAdminBundle/pull/8105)] Allow to disable `icheck` and to be able to use still choice field mask with the expanded option ([@goetas](https://github.com/goetas))

### Fixed
- [[#8100](https://github.com/sonata-project/SonataAdminBundle/pull/8100)] Logic to handle show / hide column of table html element ([@nhung-le](https://github.com/nhung-le))
- [[#8108](https://github.com/sonata-project/SonataAdminBundle/pull/8108)] Add missing type button on ModelList form widget ([@tdumalin](https://github.com/tdumalin))
- [[#8099](https://github.com/sonata-project/SonataAdminBundle/pull/8099)] `label_catalogue` configuration node deprecation message ([@7ochem](https://github.com/7ochem))

## [4.27.0](https://github.com/sonata-project/SonataAdminBundle/compare/4.26.1...4.27.0) - 2023-09-07
### Added
- [[#8083](https://github.com/sonata-project/SonataAdminBundle/pull/8083)] Autocomplete attr support for select2 ([@pietaj](https://github.com/pietaj))
Expand Down
27 changes: 27 additions & 0 deletions docs/cookbook/recipe_icheck.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,30 @@ set data attribute ``data-sonata-icheck = "false"`` to this form element::
.. note::

You have to use false as string! ``"false"``!

When using ``Sonata\AdminBundle\Form\Type\ChoiceFieldMaskType`` (or other types that inherit from it)
with the ``expanded``: ``true`` option (that renders the form type with checkboxes or radio buttons),
it is necessary to set the ``data-sonata-icheck`` attribute on its choice elements::

use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\AdminBundle\Form\Type\ChoiceFieldMaskType;

protected function configureFormFields(FormMapper $form): void
{
$form
->add('category', ChoiceFieldMaskType::class, [
'expanded' => true,
'placeholder_attr' => [
// the placeholder (if any) needs also the data-sonata-icheck attr too since is rendered as
// checkbox or radio button
'data-sonata-icheck' => 'false'
],
'choice_attr' => [
'val1' => ['data-sonata-icheck' => 'false'],
'val2' => ['data-sonata-icheck' => 'false'],
// ...
],
])
;
}
33 changes: 27 additions & 6 deletions src/Resources/views/Form/form_admin_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -475,20 +475,21 @@ file that was distributed with this source code.
{% set main_form_name = id|slice(0, (id|length - name|length)-1) %}
{% if expanded %}
{% set js_selector = '#' ~ main_form_name ~ '_' ~ name ~ ' input' %}
{% set js_event = 'ifChecked' %}
{% set js_events = ['change', 'ifChecked'] %}
{% else %}
{% set js_selector = '#' ~ main_form_name ~ '_' ~ name %}
{% set js_event = 'change' %}
{% set js_events = ['change'] %}
{% endif %}
<script>
jQuery(document).ready(function() {
var allFields = {{ all_fields|json_encode|raw }},
map = {{ map|json_encode|raw }},
showMaskChoiceEl = jQuery("{{ js_selector }}");
showMaskChoiceEl.on("{{ js_event }}", function () {
choice_field_mask_show(jQuery(this).val());
});
{% for js_event in js_events %}
showMaskChoiceEl.on("{{ js_event }}", function () {
choice_field_mask_show(jQuery(this).val());
});
{% endfor %}
function choice_field_mask_show(val) {
var controlGroupIdFunc = function (field) {
Expand All @@ -505,19 +506,38 @@ file that was distributed with this source code.
defaultFieldId = '#{{ main_form_name }}_' + field;
}
// catch select2 fields with inline: table option
if (jQuery(defaultFieldId).length === 0) {
defaultFieldId = '#{{ main_form_name }}_' + field + '_autocomplete_input';
}
return defaultFieldId;
};
jQuery.each(allFields, function (i, field) {
var fieldContainer = controlGroupIdFunc(field);
jQuery(fieldContainer).hide();
{% if form.parent.vars.sonata_admin.inline == 'table' %}
var td = jQuery(fieldContainer).parent();
var columnIndex = td.index();
var headerTh = $("table thead tr th:eq(" + columnIndex + ")");
td.hide();
headerTh.hide();
{% endif %}
jQuery(fieldContainer).find('[required="required"]').attr('data-required', 'required').removeAttr("required");
});
if (map[val]) {
jQuery.each(map[val], function (i, field) {
var fieldContainer = controlGroupIdFunc(field);
jQuery(fieldContainer).show();
{% if form.parent.vars.sonata_admin.inline == 'table' %}
var td = jQuery(fieldContainer).parent();
var columnIndex = td.index();
var headerTh = $("table thead tr th:eq(" + columnIndex + ")");
td.show();
headerTh.show();
{% endif %}
jQuery(fieldContainer).find('[data-required="required"]').attr("required", "required");
});
}
Expand Down Expand Up @@ -646,6 +666,7 @@ file that was distributed with this source code.
<button
onclick="return remove_selected_element_{{ id }}(this);"
class="btn btn-danger btn-sm sonata-ba-action"
type="button"
{# NEXT_MAJOR: Remove the fallback on null and on btn_catalogue #}
title="{{
btn_translation_domain|default(null) is same as(false)
Expand Down

0 comments on commit 85b19db

Please sign in to comment.