atayahmet / laravel-nestable

Laravel 5 nested category/menu generator
MIT License
214 stars 52 forks source link

selected() placeholder() in renderAsMultiple() #35

Closed adamkeygroup closed 6 years ago

adamkeygroup commented 6 years ago

My Goal is to add placeholder with value = 0 and select it.

With this code the placeholder is not selected: $categories = Category::attr([ 'class' => 'form-control error-input']) ->placeholder(['0', 'Tutte le Categorie']) ->selected([0]) ->renderAsMultiple();

I wrong something?

Obviously work if I edit NESTABLESERVICE.php (VENDOR) row 310 with: if(current($this->placeholder)) { if ($this->selected == key($this->placeholder)){ $selcted_placeholder = 'selected="selected"'; }else{ $selcted_placeholder = ''; }

$tree .= '<option '.$selcted_placeholder.' value="'.key($this->placeholder).'">' . current($this->placeholder) . ''; }

atayahmet commented 6 years ago

Hi @Sirtest

It's wrong usage. Placeholder's not to be a value usually. Selectable row should be in record set. If you have to this way, you can do this with javascript.

Also you are wrong using placeholder.

Correct usage:

$categories = Category::attr([ 'class' => 'form-control error-input'])
    ->placeholder('0', 'Tutte le Categorie')
    ->selected(0)
    ->renderAsMultiple();
adamkeygroup commented 6 years ago

Thank you

adamkeygroup commented 6 years ago

After update doesn't work with ->selected(0) or ->selected([0])

Any suggestion ?