z-song / demo.laravel-admin.org

Source code of official http://demo.laravel-admin.org website.
507 stars 250 forks source link

add SelectOrNew component #8

Closed never615 closed 6 years ago

never615 commented 6 years ago

@langeuh commented on Fri May 26 2017

select from existing values for a certain column or add a new one. if no options are given, options are filled in automatically using the unique values for the given column. By default the selection can be cleared and an empty value is prepended. You can turn it off by calling allowClear(false) on the field.

e.g.

        $form->selectOrNew('salutation’);

or specify options yourself

        $form->selectOrNew('salutation')
        ->options([
            1 => ‘sir’,
            2 => ‘misses’,
        ])
               ->rules('required')
               ->allowClear(false);

allowClear there is method to set wether you can clear the selection or not:

        $form->selectOrNew('salutation’)->allowClear();

inside a nestedForm you’ll need to dataModel() to specify on which model to get the default options from (can't seem to find the related model. Please change it if possible)

$form->selectOrNew('city')
                        ->rules('max:50|string')
                        ->attribute('maxlength', 50)
                        ->dataModel(Address::class);