Coder Social home page Coder Social logo

Comments (25)

milewski avatar milewski commented on July 22, 2024 2

That was a mistake, I didn't know macros wouldnt run in static context, I have removed it and pushed again

from conditional-container.

bernhardh avatar bernhardh commented on July 22, 2024 1

@milewski I just used the branch as well and tried the code of @dividy but i get

TypeError: Cannot read property 'join' of undefined
    at _loop (conditional-container:175)

And I even dont see the fields.

I also tried my own, simpler example with the same result:

Flexible::make("Data")
    ->addLayout("Simple Layout", "html", [
        Select::make("Type", "type")->options([
            "html" => "HTML",
            "plain" => "Plaintext"
        ]),
        ConditionalContainer::make([
            Trix::make('Content', 'html_content')
        ])->if('type = html'),
        ConditionalContainer::make([
            Textarea::make('Content', 'plain_content')
        ])->if('type = plain')
    ])

from conditional-container.

milewski avatar milewski commented on July 22, 2024 1

@dividy your example also works now for me... I think the issue were you forgot the trait

from conditional-container.

bernhardh avatar bernhardh commented on July 22, 2024 1

Ok, at least I can fix the issue with the tabs package (and all other packages based on Panel items).

In HasConditionalContainer.php:460 just add

if($field instanceof Panel && $field->data) {
    return $this->findAllFlexibleContentFields($field->data);
}

from conditional-container.

milewski avatar milewski commented on July 22, 2024 1

Pushed

from conditional-container.

bernhardh avatar bernhardh commented on July 22, 2024 1

Thank you very much, for your help, this package (and nova-mega-filter and collapsible-resource-manager). Do you have a "buy me a cup of coffee" link or something else?

from conditional-container.

milewski avatar milewski commented on July 22, 2024

Currently it doesn't work with flexible content

from conditional-container.

dividy avatar dividy commented on July 22, 2024

from conditional-container.

milewski avatar milewski commented on July 22, 2024

Yeah I used that package before too but had too many issues for my use case so I built this one instead, I have seen how the Nova Dependency Container implemented support for the flexible content on this commit: epartment/nova-dependency-container@d408149 perhaps it may be very simple to port it over... I will give it a shoot, and about the 2 issues, I don't see how conditional-container would fail in there

from conditional-container.

milewski avatar milewski commented on July 22, 2024

@dividy I got it almost working and I had pushed my proof of concept to a branch called flexible field, it works on create, on update and on details view as expected, however validation is still broken :(

from conditional-container.

dividy avatar dividy commented on July 22, 2024

Wow.. This sounds like a great step forward to something functional ;-)
I'll try to have a look at this too!

from conditional-container.

dividy avatar dividy commented on July 22, 2024

Just did a composer require digital-creative/conditional-container:dev-flexible-content

Tried the package, and I'm still having an issue inside Flexible Content...

Here's the code, can you try it on your side and tell me if it works ?

Flexible::make('Produits', 'products')
            ->addLayout('Product', 'product', [
                Select::make('Type de contrat', 'type')->options([
                    'L' => 'Location',
                    'VL' => 'Vente & Location',
                    'R' => 'Relevé',
                    'V' => 'Vente',
                    'VU' => 'Vente unique',
                ])->displayUsingLabels()->rules('required'),
    
                ConditionalContainer::make([ Text::make('Prix en Location (htva)', 'price_rent') ])
                ->if('type = L'),
              
                ConditionalContainer::make([ Text::make('Prix de Vente (htva)', 'price_sale') ])
                ->if('type = V')
                ->if('type = VU'), 
    
                ConditionalContainer::make([ 
                    Text::make('Prix en Location (htva)', 'price_rent'),
                    Text::make('Prix de Vente (htva)', 'price_sale')
                ])->if('type = VL'),
    
                ConditionalContainer::make([ 
                    Text::make('Prix du Relevé (htva)', 'price_reading'),
                ])->if('type = R'),        
            ]),

from conditional-container.

dividy avatar dividy commented on July 22, 2024

On my side, it never works, and displays all the fields when I select 'R - Relevé'.. Strange ;)

from conditional-container.

milewski avatar milewski commented on July 22, 2024

The join issue is because the HasConditionalContainer wasn't included ... but yeah indeed there are several issues, it did work for the example I had when I was developing it but using your samples has some bugs...

from conditional-container.

milewski avatar milewski commented on July 22, 2024

@bernhardh I just fixed the issues with your example you can try again it should be working perfectly now (but without validation of course)

Form View

image

Detail View

image

from conditional-container.

bernhardh avatar bernhardh commented on July 22, 2024

Oh. So stupid. Thank you!

Now I get

Method Whitecube\NovaFlexibleContent\Flexible::resolveConditionalContainer does not exist.

The

if ($flexibleContent->isNotEmpty()) {
    $this->registerFlexibleMacros($request, $flexibleContent);
}

is false, so this macro is never added?

from conditional-container.

milewski avatar milewski commented on July 22, 2024

whats the endpoint nova is trying to hit that throws that error Method Whitecube\NovaFlexibleContent\Flexible::resolveConditionalContainer does not exist. ?

from conditional-container.

bernhardh avatar bernhardh commented on July 22, 2024

It occurs on edit and detail page. And the endpoint throwing it is /nova-api/MODELNAME/ID

On

vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:103

from conditional-container.

bernhardh avatar bernhardh commented on July 22, 2024

Btw. I am on dev-flexible-content 7e5e620 atm.

Ok, found it out, that if I don't use the https://github.com/eminiarts/nova-tabs package, than it works. Wrapping it into it, throws the error. The same goes with https://github.com/armincms/json package. It seems, that the FlexibleContent Element has to be on top Level?

from conditional-container.

milewski avatar milewski commented on July 22, 2024

Oh I see when you use the nova-tabs the "flexible" content is not found, so the macros are not added to it, that's why it crashes, I think it might be possible to detect, I think it is possible to add a check and see if its an instance of panel and recursively try to find flexible contents within its children

from conditional-container.

milewski avatar milewski commented on July 22, 2024

Ah ok let me add

from conditional-container.

bernhardh avatar bernhardh commented on July 22, 2024

Ok, now it only worked on empty data. After save i get

Cannot bind an instance to a static closure

To fix this change HasConditionalContainer:178

$field::macro('generateFieldName', static function (array $fields) {

to

$field::macro('generateFieldName', function (array $fields = []) {

Not sure why it is decleared static in the first place? Or does this have any sideeffects?

from conditional-container.

dividy avatar dividy commented on July 22, 2024

Good job guys, I watched all the action from far away, getting spammed by notifications.

I had to deliver the application to my customer, so I finally chose another working option, I used different presets instead of conditional fields. However, great work!

from conditional-container.

patrickleemsantos avatar patrickleemsantos commented on July 22, 2024

@dividy Can I know what you use in order to fix this issue?

from conditional-container.

anditsung avatar anditsung commented on July 22, 2024

@dividy I got it almost working and I had pushed my proof of concept to a branch called flexible field, it works on create, on update and on details view as expected, however validation is still broken :(

if ($controller instanceof CreationFieldController ||
            $controller instanceof UpdateFieldController) {

this is the part where you check the fields for creation?


i have able to make the validation work for flexible but got other issue.

Flexible::make('Produits', 'content')
                ->addLayout('Product', 'product', [
                    Select::make('Type de contrat', 'type')->options([
                        'L' => 'Location',
                        'VL' => 'Vente & Location',
                    ])->displayUsingLabels()->rules('required'),

                    ConditionalContainer::make([
                        Text::make('Prix en Location (htva)', 'price_rent')
                            ->rules('required')
                    ])
                        ->if('type = L'),

                    ConditionalContainer::make([
                        Text::make('Prix en Location (htva)', 'price_rent'),
                        Text::make('Prix de Vente (htva)', 'price_sale'),
                    ])->if('type = VL'),
                ]),

this will make all price_rent will required

https://github.com/anditsung/conditional-container/tree/flexible-content

from conditional-container.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.