Giter Club home page Giter Club logo

nova-fields's Introduction

Getting Started

Documentation

Nova Fields is a collection of rewriten "native" fields that comes with Nova. We are also adding new fields and utilities as we find the need.

The idea here is making them more configurable and reusable in package development. These components have a lot of new methods to customize the look and feel, behavior, etc...

Vue components also emit events that propagates up to the chain so are ideal to reuse them in other Nova packages.

Looking forward to see your feedback.

Available fields:

  • ID
  • Text
  • Number
  • Textarea
  • Select
  • Password
  • Boolean
  • Trix
  • File
  • Image
  • BelongsTo
  • Currency
  • Status
  • Avatar
  • Gravatar
  • Code
  • Country
  • Date
  • DateTime
  • Markdown
  • Place
  • Timezone

Custom Fields

  • Autocomplete
  • JSON
  • Row

Install

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

Usage:

// use R64\NovaFields\<NAME OF THE FIELD>;
use R64\NovaFields\Boolean;

Boolean::make('Activo', 'active')
                ->yesLabel('Yeah')
                ->noLabel('Nope')
                ->hideLabelInDetail()
                ->dotClasses('some classes')
                ->successClass('bg-warning')

nova-fields's People

Contributors

beliolfa avatar casperlaitw avatar crynobone avatar dependabot[bot] avatar dvigueras avatar emiliogrv avatar emtudo avatar gaabora avatar jeroenherczeg avatar jonrobinson avatar krns avatar malinowskip avatar marceauka avatar matsava avatar mmanzano avatar nickpoulos avatar nikolaysav avatar pehbehbeh avatar pepeloper avatar ragingdave avatar rjvandoesburg avatar robmpreston avatar ronmelkhior avatar rorymcdaniel avatar shirshak55 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nova-fields's Issues

Validation of JSON Fields

Hi,

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?

Many Thanks,
Tom

resolveUsing not working on Row

resolveUsing is not working when applying on row's children

  Row::make('Items', [
                    Text::make("Name")->fieldClasses('w-full px-8 py-6')
                        ->hideLabelInForms()
                        ->resolveUsing(function ($value) {
                            $locale = app()->getLocale();
                            $item = json_decode($value, true);
                            return $item[$locale];
                        })->readOnly(),
                    Text::make("Quantity")->fieldClasses('w-full px-8 py-6')
                        ->hideLabelInForms()->readOnly(),
                    Text::make("Price")->fieldClasses('w-full px-8 py-6')
                        ->hideLabelInForms()->readOnly(),
                ])->hideWhenUpdating()->hideWhenCreating(),

Image field support

Thank you for your package, he is very good.
But he does not currently support Image fields, I use the Text field instead, then the text content is too long, the interface is messy;
look this:
_20180926154551

Image not working in Rows

The image url is always empty when i save my resource.
images: "[{"image":"","caption":"test"}]"
Here's the code in my resource class:

Row::make('Images', [
	Image::make('image')
		->disk('public')
		->path('images')
		->hideLabelInforms()
		->fieldClasses('w-full px-8 py-6'),
	Text::make('caption')
		->hideLabelInforms()
		->fieldClasses('w-full px-8 py-6')
	])
->hideLabelInForms()
->fieldClasses('w-full px-8 py-6'),

License?

This and your other Nova packages do not contain a license.

Do you intend adding one in the future?

Error with relationships and rows

using repeatable rows to save to a JSON field in a db. Getting this error:

   Undefined property: R64\NovaRow\Row::$resourceClass
   {"userId":1,"email":"******@gmail.com","exception":"[object] 
   (ErrorException(code: 0): Undefined property: R64\\NovaRow\\Row::$resourceClass
   at /home/vagrant/code/project/nova/src/Http/Controllers/AssociatableController.php:23)

aded package with: use R64\NovaRow\Row;, and this is the usage:

     Row::make('Questions', [
                BelongsTo::make('Questions', 'questions', Question::class)
                    ->sortable()
                    ->hideFromIndex(),
            ])

Any idea what I'm missing here? The BelongsTo field works fine without the wrapper, but won't work with it.

JSON field markup issue

Hello.
Having an issue with field names of a reasonable length (screenshot).
This can be fixed by a few markup changes (marked on the right side of the screenshot).
2018-10-20 23 48 14

Thanks for your packages. Hoping to see this fix soon.

Support for authorization on JSON subfields

I am trying authorization of JSON sub fields with something like this:

JSON::make('HelloWorld, [
    Text::make('Example')
        ->canSeeWhen('seeExample', $this),
]),

But it does not seem to have any effect.

Can you think of a simple solution for this?

Using Row field with a json attribute breaks resolving of saved data.

As you guys probably know, normally with a nova text field in combination with a json attribute I can do the following:
Works:

// In model:
protected $casts = ['content' => 'array'];

// In resource:
Text::make('Example title', 'content->exampleTitle')

But when I am trying to do this in combination with the Row field it doesn't resolve the saved value, the rows I created are not being displayed, however the data seems to be as expected in the database.
Broken:

// In model:
protected $casts = ['content' => 'array'];

// In resource:
Row::make('USPs', [
    Text::make('Line'),
], 'content->usps')

asHtml not working on computed fields

Hey, just wanted to let you know, that the asHtml ist not working as in Nova core. This will not work:

Text::make('Example', function () {
    return view('example')->render();
})->asHtml(),

The displayed contents should not be escaped.

Add a validation rule on the JSON Field itself

Doing something like
JSON::make('Others', [ Date::make("Date", "dailyMenuDate")->resolveUsing( function ($value) { return Carbon::make($value)->format('Y-m-d'); }) ], "meta") ->rules('required', new DailyMenuRule),
Works in a weird way, Create and Updates are prevented but not error message is shown

JSON Childs -> fieldClasses and labelClasses not overwrite

Hey,

fieldClasses and labelClasses at field level are ignored in Version 0.3.6 at the Update View.

Setup

at the Ressource:

JSON::make('Fieldname', $this->myFields(), 'fieldname')

Fielddefinition

public function myFields(): array
{
    return collect([
        R64Text::make(...),
        R64Boolean::make(...)
    ])
    ->each->labelClasses('w-3/5 py-4 pr-4')
    ->each->fieldClasses('w-2/5 py-4')
    ->all();
}

Bug

developerbar display the old (default) classes.

<div class="flex border-b border-40" resource-id="2">
   <div class="w-1/5 px-8 py-6">
      <label class="inline-block text-80 pt-2 leading-tight" for="Labeltext">
        Labeltext
      </label>
      <p class="text-sm leading-normal text-80 italic"></p>
   </div>
   <div class="w-1/2 px-8 py-6">
      <input id="Labeltext" dusk="email_suffix" placeholder="Labeltext" type="text" class="w-full form-control form-input form-input-bordered">
      <!---->
   </div>
</div>

Debug

Dump of Fielddefinitions:

...
    +fieldClasses: "w-2/5 py-4"
    +panelFieldClasses: "w-3/4 py-4"
    +labelClasses: "w-3/5 py-4 pr-4"
    +panelLabelClasses: "w-1/4 py-4"
...

Request from Nova (Frontend) to Laravel at Route /:resource/2/update-fields:

fieldClasses: "w-1/2 px-8 py-6"
fields: [
   0: {
    ...
    component: "nova-fields-text"
    fieldClasses: "w-2/5 py-4"
    labelClasses: "w-3/5 py-4 pr-4"
    ...

Row and BelongsTo error

Hi, with latest version a give an error with Row and BelongsTo when clicked on add row button in the create view and edit view

composer.json

"64robots/nova-fields": "^0.6.1",

My own nova resource

use R64\NovaFields\BelongsTo as CustomBelongsTo;
use R64\NovaFields\Number as CustomNumber;
use R64\NovaFields\Row;
use R64\NovaFields\Text as CustomText;

...

Row::make('Lines', [
    CustomNumber::make('Cantidad', 'quantity')
        ->fieldClasses('w-full px-8 py-6')
        ->hideLabelInForms()
        ->min(1)
        ->rules(
            'required',
            'integer',
            'min:1'
        )
        ->sortable(),

    CustomText::make('Precio', 'price')
        ->fieldClasses('w-full px-8 py-6')
        ->hideLabelInForms()
        ->rules(
            'required',
            'string',
            'regex:/^\d+((,|\.)\d{1,2})?$/'
        )
        ->sortable(),

    /**
      * Relationships
      */
    CustomBelongsTo::make('Producto', 'product', Product::class)
        ->fieldClasses('w-full px-8 py-6')
        ->hideLabelInForms(),
])
->fieldClasses('w-full px-8 py-6')
->labelClasses('w-1/2 px-8 py-6'),

view
1

2

row field validation

Hey, it seems that the sub fields of a row field are not validated. Are you planning to support this in the future?

We really need this, so we are thinking about implementing it ourselves. Maybe we can contribute via PR if you like and did not already start an implementation. Are there any pitfalls you are already aware of?

Thanks for the great package!

[Feature]Allow to append, not only override css classes

Let's say we have a textarea and want to add a css class, to shrink it:

\R64\NovaFields\Textarea::make("Öffnungszeiten", "opening_hours")
    ->inputClasses('height-75'),

where height-75 is a custom css class. But this will destroy the default layout, because it overwrites the default classe so you have to use everywhere:

\R64\NovaFields\Textarea::make("Öffnungszeiten", "opening_hours")
    ->inputClasses("w-full form-control form-input form-input-bordered py-3 min-h-textarea height-75"),

which is not really userfriendly, since you always have to look for the current css classes, have to maintain changes to these classes, etc.

Maybe add a second boolean option the the *Classes methods (inputClasses, labelClasses, etc.) do decide, if we want to append or override the default classes. Something like this:

// Same behavior like now: Overwrite it
\R64\NovaFields\Textarea::make("Öffnungszeiten", "opening_hours")
    ->inputClasses('height-75'),
// Will append, instead of overwrite
\R64\NovaFields\Textarea::make("Öffnungszeiten", "opening_hours")
    ->inputClasses('height-75', false),

Null values

The json field is saving values as null in the database

How to casts date inside json

Hello,

I have created json object as follow:

JSON::make('Meta', [
       Boolean::make('Winner')
              ->yesLabel('Yea!')
              ->noLabel('Nope'),
       Date::make('Win Date', 'win_date')
             ->format('DD MMM YYYY'),
       Number::make('Points')
             ->min(0)
             ->max(100)
       ]),

When I save the form, Date field must cast to 'date' in Eloquent model

I tried to put:

protected $casts = [
    'meta' => 'object',
    'win_date' => 'date',
];

But it didn't work, please advice,

Question on rows

Since nova-rows has been merged in this package, can we use:

Row::make('Lines', []) to make grid like forms?

Thanks.

Maximum Rows on Row Field

Working with your package for building up some page content - awesome work so far. Wondering if there is any way to set a maximum number of rows/disable the add row button on the Row field?

Forms layout

Can i use this package to make a custom form layout?

Like in nova-row?

Remove label from nova rows

When you use hideLabelInForms() and change fieldClasses the fields gets misaligned with the headers.

I think it would be best to remove the field labels, and when you change field class it will change the header size keeping the alignment.

Help text in wrong column

When I use R64\NovaFields\JSON with R64\NovaFields\Text and ->help('Some text'), the help text is placed in the wrong column.
image

Json::make('Settings', [
                Text::make('Bookons Unit', 'unit')
                ->help('The default unit (size) for Bookons, related to this project. Example: Meter, m2, kvm, Feet, Area… Can be overridden on individual items.')
                ,

Please Help me how to use belongsTo in this package. Write now i am having following error

i am using

Row::make('lineitems', [
Number::make('Quantity')
->fieldClasses('w-full px-8 py-6')
->hideLabelInForms()->rules('required'),
BelongsTo::make('Product')->fieldClasses('w-full px-8 py-6')
->hideLabelInForms(),
Number::make('Price')
->fieldClasses('w-full px-8 py-6')
->hideLabelInForms(),
])->fieldClasses('w-full px-8 py-6')
->labelClasses('w-1/5 px-8 py-6')->hideLabelInForms()->addRowText('Add Product'),


giving me error Undefine Index :fields

Json field no update

I use json field for role permissions but, I can't update... Maybe its my wrong?
In Nova/Role

JSON::make('Permissions', [
    Boolean::make('view_admin'),
]),

In Role

protected $casts = [
    'permissions' => 'array',
];

I change casts permissions to object but again dont work...

Trix editor needs @keydown.stop

There is a bug with this editor when trying to add a question mark to the text area - and what's missing is the @keydown.stop reference to stop that from happening.

<template>
    <trix-editor
        ref="theEditor"
        @keydown.stop
        @trix-change="handleChange"
        @trix-initialize="initialize"
        @trix-attachment-add="handleAddFile"
        @trix-attachment-remove="handleRemoveFile"
        @trix-file-accept="handleFileAccept"
        :value="value"
        :placeholder="placeholder"
        class="trix-content"
    />
</template>

Support for nested JSON

Thank you for this package.

I'm trying to make a simple nested json like below and getting a "trying to get price of non-object". Can you add support for nested JSON?

screenshot 2018-10-01 15 37 36

field classess

Number::make('Quantity')
->fieldClasses('w-full px-8 py-6')
->hideLabelInForms(),

fieldClasses for Number does not exist?
Having hard time in applying field and label classes? Please some documentation will be helpful.

JSON Field: No nova functions are working

If you try to use common nova functions on fields inside a json-field, it is not working. For example:

\R64\NovaFields\JSON::make('Address', [   
    // Is showing on update screen
    Text::make("City", 'city')->hideWhenUpdating(),
    
     // Is showing on detail screen
    Text::make('Postal Code', "zip")->hideFromDetail()
], 'json_data'),

Disable readonly on create

Currently the readOnly is applied on all views, but it would be nice to enable readOnlyOnUpdate as well.

how to use?

Hello, how can i use this package?

i am trying to implement " Nova BelongsTo Or Create" but cant find a documentation for how to..

i have allready installed nova fields package

element.handleChange error with belongsTo in row

Hi, when I try update a resource with a BelongsTo field into row, row issued and error

1

UPDATE
Steps to reproduce it:

Example:
An invoices previusly created with lines (products => lines/invoices details)

If try edit it, the Row component throw an error, can see it in the image above

How about addIndexClasses?

I'm trying to add "whitespace-no-wrap text-left" to the Process column.

image

Can you add a method to support something like this:

            BelongsTo::make('Process')
                ->addIndexClasses('whitespace-no-wrap text-left'),

Thanks!

resolve and fill callbacks broken for row

Maybe I'm missing something but the resolveUsing code doesn't even get hit at all? On version 0.6.1.

Adding a dd into the resolveUsing callback is never called. In fact adding a dd to either the row or the inner row fields seem to do nothing.

Snippet as an example:

       Row::make('Features and Benefits', [
            Text::make('test', null, function($feature) {
                dd('test');
            }),
            Textarea::make('Feature/Benefit', 'feature', function ($feature) {
                dd('test');
                return $feature;
            })->hideLabelInForms()
        ], 'features')

Granted I'm trying to do something like a list where the result is just an array of strings, but the logic should still be getting hit.

ADDITIONAL UPDATE: It also broke using a resolveUsing on the Row field itself. reverting back to 0.6.0 makes the row field level resolve work again

ADDITIONAL ADDITIONAL UPDATE:
Snippet for example of Row level resolve/fil working in 0.6.0 but broken completely in 0.6.1

        Row::make('Features and Benefits', [
            Textarea::make('Feature/Benefit', 'feature')->hideLabelInForms()
        ], 'features', function ($features) {
            return collect($features)->map(function ($feature) {
                return ['feature' => $feature];
            });
        })->fillUsing(function (NovaRequest $request, $model, $attribute, $requestAttribute) {
            if ($request->exists($requestAttribute)) {
                // Ensure we don't store that random row_id that gets generated
                $model->{$attribute} = collect($request[$requestAttribute])->pluck('feature')->flatten()->filter();
            }
        })->fieldClasses('w-full px-8 py-6')->hideHeading()->addRowText('Add Feature'),

I know this kind of logic isn't quite in line with how it's supposed to work, but still a very breaking change based on how fields are supposed to work in Nova.
Also noting that using the more general syntax of calling resolveUsing on the Row field also doesn't work as expected.

I figured this level of breakage deserves it's own issue rather than just piggy backing on an old closed issue #49)

any way to remove left margin?

Hello,

when I use like this:
JSON::make(false, [
Text::make('Title'),
Textarea::make('Description'),
//Tags::make('Keywords')->type('brands'),
])

any way to make that there is no padding on the left?

Add support float field

Nova doesn’t have float type field.
Maybe you can add support within this library?

I mean:

<input type="number" step="0.01">

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.