eltharin/reloadablefield 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eltharin/reloadablefield

最新稳定版本:V2.0.2

Composer 安装命令:

composer require eltharin/reloadablefield

包简介

reloadablefield Bundle for symfony

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

  • Require the bundle with composer:
composer require eltharin/reloadablefield

What is ReloadableFields Bundle?

This bundle will help you to work with reloadbale fields, it will make the ajax query and the backend for reload a form select.

The select will have a new event "reload" witch call an ajax query.

When you modify in other page the data linked to the field you can easiest reload them.

This library use junior.js, my small library for manage events, http request and other.

you can download it like this :

You nedd to have the JuniorJs suite for use this bundle :

composer require eltharin/juniorjs

Or you can use your own script by settings this configuration :

# config/packages/eltharin_reloadable_field.yaml

eltharin_reloadable_field:
  useOwnJsFile: true

if you want to use default JS for ajax query, leave useOwnJsFile parameters at false and import eltharin/twigfilesgetter for load unique Js : https://github.com/eltharin/TwigFilesGetter

by default, it adds a markup in params/after, you need to update your form theme to view it by add :

# form theme twig template

{%- block form_row -%}

...

{%- for after in params.after -%}
    {{ block(after[0]) }}
{%- endfor -%}

...

{%- endblock form_row -%}

ReloadButton HTML

By default, the HTML of the ReloadButton use fontAwesome :

'<i class="fa-solid fa-rotate fa-2x reloader" data-target="{{ id }}"></i>'

For change the ReloadButton HTML for all of your site, you can create a form template with a block named reloadablefield_reload_button :

{%- block reloadablefield_reload_button -%}
	<i class="fa-solid fa-rotate fa-2x reload_button" data-target="{{ id }}"></i>
{%- endblock reloadablefield_reload_button -%}

or for change only once, in Type Class :

'reloadbtn' => '<span class="btn success reload_button" data-target="{{ id }}" />reload</span>',

Don't forget to add reload_button class for use default js.

Bonus

How add a "add" button for launch a form popup and reload automaticly the select :

1- in Type Class : add params :

'params' => ['after' => ['<i class="fa-regular fa-square-plus openpopup  fa-2x addAndReload" data-target="{{ id }}" data-formfield="type[libelle]" href="/gestion/type/new" ></i>']]

2- with my other JS bundle : https://github.com/eltharin/juniorjs you can have the openpopup class, form will be called in ajax and print in a popup

3- by default automaticly, it add an event "onFormSubmitSuccess" executed after form submit per example:

JR.events.add('onFormSubmitSuccess','.addAndReload',  function(event)
{
    var textToSearch = "";
    if(this.dataset.formfield !== undefined)
    {
        textToSearch = event.detail.formData.get(this.dataset.formfield) || "";
    }

    JR.events.dispatch('reload', '#' + this.dataset.target, {
        "detail": {
            onReload : function (select,httprequest) {
                if(textToSearch != "")
                {
                    const optionToSelect = Array.from(select.options).find(item => item.text === textToSearch);
                    optionToSelect.selected = true;
                }
            }
        }
    });
});

统计信息

  • 总下载量: 60
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2022-08-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固