Code Monkey home page Code Monkey logo

alpinejs-multiselect's Introduction

Multiselect with Alpine.js

This project is a component called multiselect created using Alpine.js

Tech Stack

Installation

# Install packages
npm i

Run Locally

# Start Vitejs
npm run dev

Documentation

This component is inspired by the new Alpine.js components, precisely the dropdown!

In fact, in server-side framework like AdonisJS, Ruby on Rails or Laravel, having Alpine.js is such useful to create interactive components ! But why always creating components from scratch? This is why this multiselect exist, to help you!

This multiselect have keyboards navigation built-in!

The multiselect takes 2 parameters:

  • data, an array of object with id and name
  • selectedData, an array of id

Exemple:

multiselect([
    {
        id: 1,
        name: 'Option 1',
    },
    {
        id: 2,
        name: 'Option 2',
    },
    {
        id: 3,
        name: 'Option 3',
    },
    {
        id: 4,
        name: 'Option 4',
    },
    {
        id: 5,
        name: 'Option 5',
    },
], [1, 3])

But, because you will copy-paste this component, feel free to update data to your to your needs!

How to use with a template engine

Using a template engine is easy now.

With Edge:

multiselect({{ stringify(data) }}, {{ stringify(selectedData) }})

With PHP:

multiselect(<?= json_encode(data)  ?>, <?= json_encode(selectedData) ?>)

And your multiselect will works on client-side!

Can I use it in a form

Yes! You can use it in a form because a select with multiple attribut is updated in realtime using the selected data.

 <select multiple="multiple" name="alpine[]" hidden>
    <template x-for="id in selected" :key="id">
        <option selected :value="id"></option>
    </template>
</select>

Examples

You can test this component at this url

Contributing

Contributions are always welcome!

Feel free to provide feedbacks !

Authors

alpinejs-multiselect's People

Contributors

barbapapazes avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.