Giter VIP home page Giter VIP logo

chain's Introduction

chain

Conditionally load a field with the value of the other fields.

Installation

Via composer: composer require armincms/chain.

Usage

The Chain field works as a trigger and listener. a trigger chain listens to the update events of entire fields and the listener chain listening to the trigger Chain events and its entire fields together.

Make trigger field

The trigger Chain initializes via the as method. the as method accepts two arguments. the first argument is the name of event and the second argument is a fields callback. it receives a request instance for resolving fields.

        Chain::as('name', function() {
            return [ 
                Text::make('Name')
                    ->sortable()
                    ->rules('required', 'max:255'), 

                Text::make('Username')
                    ->sortable()
                    ->rules('required', 'max:255'), 
            ];  
        }), 

Make listener field

The listener Chain initializes via the with method. the with method accepts an array of events as the first argument and a callback for the fields as second arguemnt. for listening to a trigger Chain you should pass the name of the Chain as the event name. for listening to a field of a trigger Chain you can prefix the field name by the Chain name and listen to it. for example, you can listen to the name field of a Chain (Chain field named by the 'test'), with the test.name event.

        Chain::with('name', function($request) {
            if($request->filled('username')){
                return [ 
                    Text::make('Password')
                        ->sortable()
                        ->rules('required', 'max:255'), 
                        
                    Text::make('Confirmation')
                        ->sortable()
                        ->rules('required', 'max:255'), 
                ];  
            }
            
            return [];
        }, 'second-chain'), 

        
        Chain::with('second-chain.confirmation', function($request) {
            return [ 
                Boolean::make('Passed')
                  ->readonly()
                  ->withMeta(['value' => 1]), 
            ]; 
        }),

chain's People

Contributors

zareismail avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.