Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Fix validation and update process.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Aug 25, 2019
1 parent 4745e45 commit 850000b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 28 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.1.9] - 2019-08-02
## [0.1.10] - 2019-08-25
### Fixed
- updating of existing coordinates.
- validation when field names were not default `latitude` and `longitude`.

## [0.1.9] - 2019-08-20
### Added
- default Zoom, Lat, Long settings.

Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ use GeneaLabs\NovaMapMarkerField\MapMarker;
MapMarker::make("Location"),
```

### Model Fields
### Coordinate Field Names
By default the field will look for `latitude` and `longitude` fields on the
model. However, if your model uses different names, you may customize them with
the `->latitude('lat')` and `->longitude('long')` methods:
```php
MapMarker::make("Location")
->latitude('lat')
->longitude('long')
->defaultZoom(8)
->defaultLatitude(41.823611)
->defaultLongitude(-71.422222),
->longitude('long'),
```

### Default Settings
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

15 changes: 3 additions & 12 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default {
data: function () {
return {
defaultLatitude: this.field.defaultLatitude || 0,
defaultLongitude: this.field.defaultLongitude || 0,
defaultZoom: this.field.defaultZoom || 12,
tileUrl: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
geosearchOptions: {
provider: new EsriProvider(),
Expand Down Expand Up @@ -68,18 +71,6 @@ export default {
},
computed: {
defaultLatitude: function () {
return this.field.defaultLatitude || 0;
},
defaultLongitude: function () {
return this.field.defaultLongitude || 0;
},
defaultZoom: function () {
return this.field.defaultZoom || 12;
},
firstLocationError: function () {
if (this.hasLocationError) {
return (this.errors.first(this.latitudeFieldName)
Expand Down
21 changes: 12 additions & 9 deletions src/MapMarker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ public function __construct($name, $attribute = null, callable $resolveCallback

protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute)
{
foreach ($requestAttribute as $field) {
if ($request->exists($field)) {
$model->{$field} = json_decode($request[$field], true);
foreach ($requestAttribute as $field => $modelField) {
if (in_array($field, ["latitude", "longitude"])
&& $request->exists($modelField)
) {
$model->{$modelField} = json_decode($request[$modelField], true);
}
}
}

public function getRules(NovaRequest $request)
{

return [
"latitude" => is_callable($this->rules)
$this->attribute["latitude"] => is_callable($this->rules)
? call_user_func($this->rules, $request)
: $this->rules,
"longitude" => is_callable($this->rules)
$this->attribute["longitude"] => is_callable($this->rules)
? call_user_func($this->rules, $request)
: $this->rules,
];
Expand All @@ -41,10 +44,10 @@ public function getRules(NovaRequest $request)
public function getCreationRules(NovaRequest $request)
{
$rules = [
"latitude" => is_callable($this->creationRules)
$this->attribute["latitude"] => is_callable($this->creationRules)
? call_user_func($this->creationRules, $request)
: $this->creationRules,
"longitude" => is_callable($this->creationRules)
$this->attribute["longitude"] => is_callable($this->creationRules)
? call_user_func($this->creationRules, $request)
: $this->creationRules,
];
Expand All @@ -58,10 +61,10 @@ public function getCreationRules(NovaRequest $request)
public function getUpdateRules(NovaRequest $request)
{
$rules = [
"latitude" => is_callable($this->updateRules)
$this->attribute["latitude"] => is_callable($this->updateRules)
? call_user_func($this->updateRules, $request)
: $this->updateRules,
"longitude" => is_callable($this->updateRules)
$this->attribute["longitude"] => is_callable($this->updateRules)
? call_user_func($this->updateRules, $request)
: $this->updateRules,
];
Expand Down

0 comments on commit 850000b

Please sign in to comment.