Giter VIP home page Giter VIP logo

nova-json's Introduction

Important

This field has been merged to Custom Nova Fields package. Keep track of it for updates!

JSON Field for Laravel Nova

This field allows you to group together Nova Fields and merge their key => value pairs into unique JSON.

Demo

Demo

Install

Run this command in your nova project: composer require 64robots/nova-fields

Add it to your Nova Resource:

Create a new Json field passing an array of Nova Fields as second param

use R64\NovaFields\JSON;


JSON::make('Content', [
              Text::make('Name'),
              Boolean::make('Active'),
              Textarea::make('Description'),
          ]),

Attribute name can be passed as third param

use R64\NovaFields\JSON;


JSON::make('Content', [
              Text::make('Name'),
              Boolean::make('Active'),
              Textarea::make('Description'),
          ], 'content_json'),

This converts to

{ "name": "Jane", "active": true, "description": "My Description" }

and is stored in the content_json field.

In this example ensure that the content_json field is being set to cast to object on the underlying model instance.

nova-json's People

Contributors

beliolfa avatar robmpreston avatar ragingdave avatar mink avatar

Stargazers

Alexander Agasiev avatar Nooshin Taghavi avatar Huy Nguyen avatar Hasnat Babur avatar Alex Younger avatar Timo Mühlbach avatar michael ntow avatar Craig Cartmell avatar Benjamin Schlottau avatar omar hendawi avatar caizhigang avatar James avatar Jan Kremlacek avatar Igor Markin avatar Osman Zeki avatar Jordan Hall avatar Ian Hawes avatar Kit Burton-Senior avatar Liam Cottle avatar Bruno Tomé avatar Arthur Monney avatar Connor S. Parks avatar Phil-Bastian Berndt avatar TJ McKenzie avatar Daniele Sesoldi avatar  avatar Richard Klein avatar

Watchers

James Cloos avatar  avatar  avatar

nova-json's Issues

width on inner fields seems off

I was using this with the https://github.com/Silvanite/novafieldcheckboxes field and the checkboxes get all scrunched due to w-1/2 getting applied to the inner field. I'm not sure if this is default field styling but it makes it so that larger fields are scrunched. Perhaps this should actually be fixed in the checkboxes field, but since this would be the parent element, I figured that perhaps this can be addressed here.

Respect displayUsing on fields

First of all: Thanks for the great package and the latest update with support for resolveUsing(...).

Any plans to also support displayUsing(...)? That does not seem to work... 🤔

Markup Issue

Hello!

Using your package i've encountered a markup issue with longish json key names.
Screenshot attached.

screenshot at sep 22 00-23-56

Error when value is null

An error gets returned if the value is null in the Resolve method:
json_decode() expects parameter 1 to be string, array given
In
$this->value = is_object($value) ? $value : json_decode($value);

Validation

Seems like the JSON fields are not validated. Would be really great to support this.

Is this something you are planning to implement in the future?

Renaming field name ?

I think field name should be JSON instead of Json . This caused me 20 minutes debugging. I should have identified when namespace was not being imported.

merge this with nova-fields?

Any reason not to just merge this with the nova-fields package? It would make for one less loaded provider and enable the awesome customization available to those fields with styling classes.

Support for array casting

Is there any way your package could add support for array casting?

I currently use a JSON column in my database which is cast to an array using the $casts attribute on my model.

When using nova-json the value sent to the field is already a valid JSON string, which throws an error when it is being parsed. This is pretty easy to fix by simply checking if the field value is an object or a string before parsing it.

The second issue is a bit harder to change, which is why I did not send a PR.
When submitting the form the value is stringified to a json string which is then parsed again by Laravel (because of the mutator) before updating the database.

Would it be possible to add an option to the field saying which cast is used, if any?

If the field is casted to an array then the Vue component shouldn't be dealing with JSON encoding/decoding.

I currently use a custom getter/setter which encode/decode the field accordingly but it seems a bit overkill...

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.