codebykyle / calculated-field

A Server Side Calculated Field for Laravel Nova

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

other fieldtypes

Dontorpedo opened this issue · comments

Hi,

It would be nice if other Fieldtypes had also a broadcast method..
something like.

Place::make()->broadcaster()

and so on...
do you thin this is possible?

thanks

I think this would be a bit difficult. The default Nova fields do not broadcast an event, and the only way to enable a ->broadcaster() feature would be to replace the built-in components, or extend Nova's primary repository to enable a hook on the value.

I will look into this once I get some time.

@Dontorpedo

I followed @codebykyle instructions here, and created my own custom local package having other broadcaster and listener field types. Here's an example of the folder structure of my package:

├── resources
│   ├── js
│   │   ├── components
│   │   │   ├── broadcaster-belongs-to-field
│   │   │   │   └── FormField.vue
│   │   │   ├── broadcaster-boolean-field
│   │   │   │   └── FormField.vue
│   │   │   ├── broadcaster-text-field
│   │   │   │   └── FormField.vue
│   │   │   ├── listener-belongs-to-field
│   │   │   │   └── FormField.vue
│   │   │   └── listener-text-field
│   │   │       └── FormField.vue
│   │   ├── field.js
│   │   └── mixins
│   │       └── Listener.vue
│   └── sass
│       └── field.scss
├── routes
│   └── api.php
├── src
│   ├── Http
│   │   └── Controllers
│   │       └── CalculatedFieldController.php
│   ├── Traits
│   │   ├── Broadcaster.php
│   │   └── Listener.php
│   ├── BroadcasterBelongsTo.php
│   ├── BroadcasterBoolean.php
│   ├── BroadcasterNumber.php
│   ├── FieldServiceProvider.php
│   ├── ListenerBelongsTo.php
│   ├── ListenerNumber.php
│   └── ListenerText.php
commented

@pauldstar would you be so kind to share your nova-components code?

@latwelve

Sure. I'll create a repo and share it shortly.

commented

@latwelve uploaded to this repo: https://github.com/pauldstar/calculated-field

thank you - I've just had a quick look is it missing ListenerBoolean?

@latwelve Yeah it's missing. I've only added field types that I've needed thus far. I could add it if you fancy.

commented

@latwelve Yeah it's missing. I've only added field types that I've needed thus far. I could add it if you fancy.

Ah ok no worries - I should be able to add extra fields in too, new to laravel and nova so it's a good exercise thanks for getting me started

@latwelve Fantastic. Have fun.

@pauldstar Hello, great extension you built there. It is not available on composer, so my question is how can i install your package? Can you give me some keywords so I can search for a tutorial? Thanks

Hello @marcusgabler

Sorry for late reply. It used to be on composer, but i took it off, because I made so many modifications to it, and didn't have time to keep updating. Plus I've merged it with another custom package that I made for UI at work. So I didn't feel comfortable dishing out a half finished product.

So I've just left the repo as public, so others can study and add to their code as they see fit.

Looking to use this for a Select. If anyone has experimented with this can you please let me know. Thank you.

@keironwaites

I've updated my repo with a Select (ReactiveSelect.php, ReactiveSelect.vue).

@pauldstar Wow! Nice one, thank you. I will try it out hopefully this afternoon.

Apologies for my lack of knowledge but does anyone have any guides on how to manually install this package using composer? I assume this is the correct approach? Cheers.

I managed to install the package. I am using Example.php's example on a cleanish Resource. I get the following JavaScript error when changing the Price Control drop down.

Screenshot 2020-10-23 at 16 36 08

What am I missing? Cheers

@keironwaites

Sorry, my repo isn't a package (it was at some point, but i removed it...no time to maintain).

And Example.php is not really functional lol it's just to show how to use the custom fields you have created (or in this case copied).

The original intent for this code was to create custom fields which help people who had followed @codebykyle instructions on how to do just that. The instructions can be found here.