Skip to content

Commit

Permalink
Fix validation bug with ~
Browse files Browse the repository at this point in the history
  • Loading branch information
dvlpp committed Nov 3, 2015
1 parent bb2ccf9 commit f2e666d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion resources/views/cms/partials/formField.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@if(!in_array($field->type, ["hidden", "javascript"]))

<div class="form-group sharp-field sharp-field-{{ $field->type }} sf-{{ $key }} col-md-{{ $field->field_width ?: '12' }}"
<div class="form-group sharp-field sharp-field-{{ $field->type }} {{ key_name_for_form_field($key) }} col-md-{{ $field->field_width ?: '12' }}"

{{ $field->conditional_display ? 'data-conditional_display='.$field->conditional_display : '' }} >

Expand Down
19 changes: 19 additions & 0 deletions src/Dvlpp/Sharp/Http/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Dvlpp\Sharp\Exceptions\InvalidStateException;
use Dvlpp\Sharp\Repositories\SharpCmsRepository;
use Illuminate\Contracts\Support\MessageBag;
use Illuminate\Http\Request;
use Dvlpp\Sharp\Config\SharpConfig;
use Illuminate\Contracts\Auth\Access\Gate;
Expand Down Expand Up @@ -344,6 +345,8 @@ private function save($categoryName, $entityName, Request $request, $id)
], 200);

} catch (ValidationException $e) {
$this->formatValidationErrors($e->getErrors());

return response()->json($e->getErrors(), 422);
}
}
Expand Down Expand Up @@ -385,4 +388,20 @@ private function fireEvent($entityConfig, $eventName, $params)
}
}

/**
* Format validation errors, handling ~ special case.
*
* @param MessageBag $validationErrors
*/
private function formatValidationErrors(MessageBag $validationErrors)
{
$errors = [];
foreach($validationErrors->keys() as $key) {
$errors[str_replace("~", "-", $key)] = $validationErrors->get($key);
}
if(count($errors)) {
$validationErrors->merge($errors);
}
}

}
4 changes: 3 additions & 1 deletion src/Dvlpp/Sharp/Validation/SharpValidator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Dvlpp\Sharp\Validation;
<?php

namespace Dvlpp\Sharp\Validation;

use Validator;
use Dvlpp\Sharp\Exceptions\ValidationException;
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/sharp_internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,10 @@ function get_file_path($relativePath, $disk='local')
$storagePath = Storage::disk($disk)->getDriver()->getAdapter()->getPathPrefix();

return $storagePath . $relativePath;
}

function key_name_for_form_field($key)
{
$key = str_replace("~", "-", $key);
return "sf-$key";
}

0 comments on commit f2e666d

Please sign in to comment.