Home > Software engineering >  Unable to retrieve data from parent form in InlineCreate operation in backpack for laravel
Unable to retrieve data from parent form in InlineCreate operation in backpack for laravel

Time:04-30

I implement the InlineCreate Operation in Backpack for Laravel and works fine, but my field depend of other field and I can't to get the parent field information in the modal or in the setup operation.

Field Definition

$this->crud->addField([
    'name' => 'cliente_contacto',
    'type' => "relationship",
    'ajax' => true,
    //'inline_create' => true,
    'inline_create' => [ // specify the entity in singular
        'entity' => 'cliente_contacto', // the entity in singular
        // OPTIONALS
        'force_select' => true, // should the inline-created entry be immediately selected?
        'modal_class' => 'modal-dialog modal-lg', // use modal-sm, modal-lg to change width
        'modal_route' => route('cliente-contacto-inline-create'), // InlineCreate::getInlineCreateModal()
        'create_route' => route('cliente-contacto-inline-create-save'), // InlineCreate::storeInlineCreate()
        'include_main_form_fields' => ['proyecto'] // pass certain fields from the main form to the modal
    ],
    // 'data_source' => backpack_url('presupuesto/fetch/cliente-contacto'),
    // 'placeholder' => 'Seleccione un elemento',
    'minimum_input_length' => 0,
    'dependencies' => ['cliente'], // when a dependency changes, this select2 is reset to null
    //'method'                    => 'POST', // optional - HTTP method to use for the AJAX call (GET, POST)
    //'include_all_form_fields' => true, //sends the other form fields along with the request so it can be filtered.
    'tab' => 'Datos Principales',
    'wrapper' => [
        'class' => 'col-md-3'
    ]
]);

ClienteContactoCrudController

protected function setupInlineCreateOperation()
{
   $parent_loaded_fields = request()->get('parent_loaded_fields');
}

But I can't get that fields. The documentation: https://backpackforlaravel.com/docs/5.x/crud-operation-inline-create#how-to-use-1

'include_main_form_fields' => ['field1', 'field2'], // pass certain fields from the main form to the modal

Don't said how get that values.

I found this: https://github.com/Laravel-Backpack/CRUD/issues/2925#issuecomment-644060749

I can get:

'entity' => request()->get('entity'),
'modalClass' => request()->get('modal_class'),

But

'parentLoadedFields' => request()->get('parent_loaded_fields')

Don't work

How can I get de parent field values?

CodePudding user response:

you should get them with request('main_form_fields').

I've just submitted a PR to the docs to reference that: https://github.com/Laravel-Backpack/docs/pull/341

Cheers

  • Related