robsontenorio / mary

Laravel Blade UI Components for Livewire 3
https://mary-ui.com
Other
961 stars 115 forks source link

Choices #6

Closed groxw closed 1 year ago

groxw commented 1 year ago

Hello, I've implemented choices but there's no scroll down to select the other option, it only shows item in the page view

robsontenorio commented 1 year ago

@groxw Please, share your code and more context.

groxw commented 1 year ago

Screenshot_731 It has more than 50 option but it only shows 2 option,

I try to visit https://choices-js.github.io/Choices/ Screenshot_732

robsontenorio commented 1 year ago

@groxw

1) Could you send again first image with more height? It seems to be overflowed by the next element on screen.

2) When you use searchable it is supposed to be used as async search on large lists, where user will type something to quick search an option. Personally I would limit the search() method to a few records like 5 to 10.

But, in any case a scroll would be useful if you would like do display dozen of items.

groxw commented 1 year ago

Screenshot_733 the function of searchable is working but, when i try to scroll down for a option, it only shows, is it possible to add scrolldown without using searchable?

robsontenorio commented 1 year ago

@groxw Yes, definitively I will add a scroll.

For now, just add extra height at end of this page, to make more room to display more items.

Here

image
groxw commented 1 year ago

Thank you, it is amazing package i think,

robsontenorio commented 1 year ago

@groxw Just released 0.33.2. Please, update and let me know if everything is ok.

Note: In your case you will need extra room at end of page anyway. Because it is the last element of screen.

groxw commented 1 year ago

` Problem 1

when i try to update i found

robsontenorio commented 1 year ago

@groxw Do not try manually change composer.json. Update package means install it again with composer require robsontenorio/mary

groxw commented 1 year ago

Thankyou! It works properyly, I wonder, is is possble to Computed Properties?

robsontenorio commented 1 year ago

@groxw i am afraid it is about Livewire. Not this package.

groxw commented 1 year ago

Screenshot_472 Hello, Is it possible that input for a choices is more elastic while i add, it is like Screenshot_473

robsontenorio commented 1 year ago

@groxw I will address this on next release.

groxw commented 1 year ago

Thanks, this package is really helpful for me

groxw commented 1 year ago

I've found some trouble in here, well I try to fill the id with mount function public function mount() { $this->user_id = [22, 23]; //ID of user_id }

In my choices : label="Siswa" wire:model="user_id"

                                    :options="$all_siswa"
                                    option-label="name"

                                    searchable

                                    >

It's selected but it doesnt display : Screenshot_474

robsontenorio commented 1 year ago

@groxw are you sure that field name exists on your model ?

option-label="name"

groxw commented 1 year ago

Yes, The table users has a name column,

robsontenorio commented 1 year ago

Your collection is :options="$all_siswa" , so that column name must exist on that collection.

groxw commented 1 year ago

yes, it works properly when I select it, but when I try to fill an user_id by mount function, it's only selected and doesnt show any display, I try to fill in by ID of User (Adissya), public function mount() { $this->user_id = [23 ]; //ID of user_id } 23 is the ID of Adissya

Screenshot_475

robsontenorio commented 1 year ago

@groxw It is supposed to work like that.

Once you have initial selection like public $user_ids = [1, 2, 3];

You MUST to change your search() method to consider include all pre selected users, besides the search value itself, because it is responsible to fill the options list.

Note :

single choice public $user_id = 4; multiple choice public $user_ids = [1, 2, 3];

groxw commented 1 year ago

So it won't be able to show display option-label when I try to make initial value?

robsontenorio commented 1 year ago

The <x-choices> needs a list of options. In some way you must determine what items will be in the list.

You MUST to change your search() method to consider including all pre selected users, besides the search value itself, because it is responsible to fill the options list.

public function search(string $value){

    // Load initial users from `public $users_id = [1,2,3];`
    $preUsers = User::whereIn('id', $this->users_id)->get();

   // search THEN append $preUsers
   // Because the search() is responsible for fill options list
    $this->users = User::where('name', 'like', "%{$value}%")->take(10)->get()->merge($preUsers);

}
groxw commented 1 year ago
public function mount()
{
    $this->user_id = [23];
    $this->all_siswa = User::role('siswa')->where('group_id', $this->user->group_id)->get();
}

public function search(string $value = '') 
{

    $preUsers = User::whereIn('id', $this->user_id)->get();
    $this->all_siswa = User::search($value)
                      ->get()
                      ->append($preUsers);
}

and my blade :

                                    <x-choices
                                    label="Siswa"
                                    wire:model="user_id"
                                    :options="$all_siswa"
                                    searchable

                                    >

It's still not showing any display in input, but it's selected when i try to open option of choices, what am i missing ? then when i try to search it return error because the function of 'append' it gives a collection not array_merge(): Argument #2 must be of type array, Illuminate\Database\Eloquent\Collection given

robsontenorio commented 1 year ago

@groxw It was a bug on choices int. Just released "0.33.3". Please, upgrade.

And change ->append($preUsers) to ->merge($preUsers). It is Laravel collection stuff, so you can include it wherever you want.

groxw commented 1 year ago

well thanks! its working

robsontenorio commented 1 year ago

@groxw Just fixed on "0.33.4" multiple choices auto grow. Upgrade and try it.

image
groxw commented 1 year ago

Sure! Thanks @robsontenorio, it's really great UI

bucari commented 1 year ago

Hi, i have the same problem using choices not displaying any result

my blade is

                        <x-choices 
                            label="Autore"  
                            wire:model="user_id"  
                            :options="$users"       
                            search-function="searchAutore"
                            no-result-text="Nessun risultato trovato..."
                            searchable />

and searchAutore function

    public function searchAutore(string $value = '') {

        $this->users = User::where('name', 'ilike', '%'. $value . '%')
                ->get();
    }

What's wrong?

Then, in my opinion, it shouldn't display the scroll bar when there's no result to display

groxw commented 1 year ago

Have you declare of variable $users in mount()? $this->users = User::all();

robsontenorio commented 1 year ago

@bucari see this https://github.com/robsontenorio/mary/issues/6#issuecomment-1704318807

robsontenorio commented 1 year ago

@bucari Just improved Choices docs. See a more comprehensive example about multiple searchable https://mary-ui.com/docs/components/choices#searchable

image
bucari commented 1 year ago

Hi, i think this is not a good solution, my users table has over 22.000 records, and i don't want to load all users in the mount function. If x-choice i ssearchable, in my case, it should reamain empty until i write something to search.

robsontenorio commented 1 year ago

@bucari did you notice ->take(x) ?

bucari commented 1 year ago

ok i use it in this way

    public function searchAutore(string $value = '')
    {
        if (strlen($value)>=3) {
            $this->users = User::query()
                ->where('name', 'ilike', "%" . $value . "%")
                ->orderBy('cognome')
                ->get();

        }
        else
            $this->users = User::query()
            ->where('name', 'ilike', "%" . $value . "%")
            ->take(0)
            ->orderBy('cognome')
            ->get();

        $preUser = null;
        if ($this->user_id) {
            // Also load selected users, besides result search
            $preUser = User::find($this->user_id)->get();

            $this->users->merge($preUser); // <--- make it appear on list
        }

    }

but i think it shouldn't run a query at all