mikebronner / nova-map-marker-field

Provides an visual interface for editing latitude and longitude coordinates.
MIT License
131 stars 36 forks source link

Better nullable support #46

Open theianjohnson opened 3 years ago

theianjohnson commented 3 years ago

Currently I can allow nullable with

MapMarker::make('Location')
    ->latitude('lat')
    ->longitude('lng')
    ->nullable()
    ->nullValues([0])

But if the map is moved at all it's impossible to re-nullify it, can we get a button to clear or reset the map? In my case the lat/lng is conditional so even accepting 0 as null was a compromise as that is a real lat/lng.

mikebronner commented 3 years ago

Hi @theianjohnson, thanks for bringing up that use-case. I will look into it. Will also be happy to accept a PR, if you have the time. :)

citricguy commented 2 years ago

You could create a Nova Action to re-nullify the field. Not as slick as a button in the editor, but is working for me at the moment.

For example:

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
        foreach ($models as $model) {
            $model->lat = null;
            $model->long = null;
            $model->save();
        }
    }