定制 nodus-it/livewire-forms 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nodus-it/livewire-forms

Composer 安装命令:

composer require nodus-it/livewire-forms

包简介

A awesome package for easy dynamic forms with Laravel Livewire and Bootstrap v4

README 文档

README

License Latest Stable Version Total Downloads Unit-Tests codecov

An awesome package for easy dynamic forms with Laravel Livewire and Bootstrap v4.

Some special input types may require external javascript dependencies (besides Bootstrap).

The following inputs are currently supported:

  • Checkbox
  • Code (requires CodeMirror.js)
  • Color
  • Date
  • Datetime (composed of a date and a time input)
  • Decimal/Money (own implementation with currency and custom unit support)
  • File
  • Hidden
  • Number
  • Password
  • Radio (Bootstrap radio button group)
  • RichTextarea (requires Quill.js)
  • Select (requires bootstrap-select)
  • Text
  • Textarea
  • Time
  • It's also possible to create your own custom input types...

Installation

You can install the package via composer:

composer require nodus-it/livewire-forms

Include the JavaScript after the @livewireScripts directive on every page that will be using Livewire.

...
<body>
    ...
    @livewireScripts
    <script src="{{ asset( 'livewire-forms/livewire-forms.js' ) }}"></script>
</body>
</html>

You can publish the config file with:

php artisan vendor:publish --provider="Nodus\Packages\LivewireForms\LivewireFormsServiceProvider" --tag="livewire-forms:config"

You can publish the blade views with:

php artisan vendor:publish --provider="Nodus\Packages\LivewireForms\LivewireFormsServiceProvider" --tag="livewire-forms:views"

Usage

Minimal form view example

class UserForm extends FormView
{
    public function inputs()
    {
        $this->addText('name')
            ->setValidations('required|unique:users,name')
            ->setSize(4);
        $this->addSelect('country')
            ->setOptions(['DE' => ['label' => 'DE']])
            ->setValidations('required')
            ->setDefaultValue('DE');
        $this->addInput(CustomFileUploadInput::class, 'picture')

        $this->addSection('tenants.views.contact');
        $this->addText('email')
            ->setValidations('required|email');
        $this->addText('phone')
            ->setValidations('required');
    }

    public function submitCreate(array $values)
    {
        User::query()->create($values);
    
        return redirect()->back();
    }

    public function submitUpdate(array $values, User $user)
    {
        $user->update($values);
        
        return redirect()->back();
    }
}

View integration

Add your created form like any other Livewire component to your blade templates:

<livewire:user-form />

In case you want to prepopulate the input fields with an existing dataset, pass the desired model or array as attribute:

<livewire:user-form :model-or-array="$user" />

If you need to pass some custom data inside your forms, you can do so by passing additional data as array via the "additional-view-parameter" attribute:

<livewire:user-form :additional-view-parameter="['customKey' => 'customData']" />

All the given additional parameter can then be acccess directly in your form like so:

public function submitCreate(array $values)
{
    $this->customKey // resolves via __get() Magic to "customData"
}

Roadmap/TODO

  • File input
  • All Inputs
    • improve multiple support
    • check if we should support more properties
    • custom property system
  • New inputs
    • High-level input types e.g. Phone or Email (incl. automatic validation and input mode defaults)
    • Maybe add also support for native select inputs
  • Extensibility
    • override default classes (class overload)
    • external extensions (e.g. remote select)
  • Post Handling
    • Validation: add support for array validation rules
    • Improve validation exception handling if such is thrown inside the submit methods
  • Find another solution for the integration of external plugins like bootstrap-select than using "wire:ignore" due to several drawbacks that come with this, such as no possibility for dynamic select option updates.

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 2.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-11-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固