whitecube / nova-flexible-content

Flexible Content & Repeater Fields for Laravel Nova
MIT License
790 stars 234 forks source link

onlyOnForms() not working within Layouts #167

Open flatcapco opened 4 years ago

flatcapco commented 4 years ago

It appears that novas field conditional view logic isn't working when a field is called from within a Layout:

Calling layout:

Flexible::make('Examples')
>addLayout(\App\Nova\Flexible\Layouts\ExampleLayout::class),

Field within this layout: Text::make('Name')->onlyOnForms(),

voidgraphics commented 4 years ago

Thanks for reporting 👍

Do you happen to know if the same happens with onlyOnIndex and onlyOnDetail?

rmsj commented 4 years ago

I won't behave with any of the "hide" options. I've opened a ticket for it but then I've noticed this one. I suppose it can be handled here.

kamilkozak commented 4 years ago

Same issue here

voidgraphics commented 4 years ago

I have pushed a partial fix for this - now fields that should be hidden on the detail page are indeed hidden. But we must apply the same fix for the other pages - sadly I don't have time to handle that today. It should be fairly similar to what I have done though.

Abdukhaligov commented 4 years ago
public function fields(Request $request) {
    $field_action = substr($request->getPathInfo(), strrpos($request->getPathInfo(), '/')+1);

    $fields = array(
        ID::make()->sortable(),
        Media::make('Banners', 'banners'),
        NovaTinyMCE::make('Description'),
    );

    if ($field_action == "update-fields" || $field_action == "creation-fields") {
      return $fields = array_merge($fields, array(
          Flexible::make('Program')
              ->addLayout('Day', 'day', [
                  DateTime::make('Event Date', 'event_begin')
                      ->resolveUsing(function ($date) {
                        return Carbon::parse($date);
                      })
                      ->format('DD MMM Y hh:mm:ss')
                      ->required(),
              ])
      ));
    } else {
      return $fields;
    }
  }
Fabio1988 commented 4 years ago

same issue here

Blindmikey commented 3 years ago

Ran into this issue due to Nova's only way to Select::make()->displayUsing() with HTML is: https://github.com/laravel/nova-issues/issues/644#issuecomment-458807921

Blindmikey commented 3 years ago

Alternative solution might be to support

in addition to fields() in layouts

https://nova.laravel.com/docs/3.0/resources/fields.html#dynamic-field-methods