Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Grid work within Form Group #485

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@
"sortablejs": "^1.15.0",
"vue-loader": "^16.8.3",
"vuex": "^4.0.2"
},
"dependencies": {
"laravel-nova-ui": "^0.4.12"
}
}
2 changes: 1 addition & 1 deletion resources/js/components/FormGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default {
return classes;
},
containerStyle() {
let classes = ['grow', 'border-b', 'border-r', 'border-l', 'border-gray-200', 'dark:border-gray-700', 'rounded-b-lg'];
let classes = ['grow', 'border-b', 'border-r', 'border-l', 'border-gray-200', 'dark:border-gray-700', 'rounded-b-lg', 'flex', 'flex-wrap'];

if (! this.group.title) {
classes.push('border-t');
Expand Down
29 changes: 27 additions & 2 deletions src/Http/Middleware/InterceptFlexibleAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@ class InterceptFlexibleAttributes
use ParsesFlexibleAttributes;
use TransformsFlexibleErrors;

/**
* Parse any flexible inputs within the given request
*
* @param array $inputs
* @return array
*/
protected function parseRequestInput($inputs)
{
if ($this->hasParsableFlexibleInputs($inputs)) {
foreach ($this->getParsedFlexibleInputs($inputs) as $input => $value) {
$inputs[$input] = $value;
}
}

foreach ($inputs as $input => $value) {
if (is_array($value)) {
$inputs[$input] = $this->parseRequestInput($value);
}
if ($input === FlexibleAttribute::REGISTER) {
unset($inputs[$input]);
}
}

return $inputs;
}

/**
* Handle the given request and get the response.
*
Expand All @@ -27,8 +53,7 @@ public function handle(Request $request, Closure $next): Response
return $next($request);
}

$request->merge($this->getParsedFlexibleInputs($request));
$request->request->remove(FlexibleAttribute::REGISTER);
$request->request->replace($this->parseRequestInput($request->input()));

$response = $next($request);

Expand Down
30 changes: 25 additions & 5 deletions src/Http/ParsesFlexibleAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Whitecube\NovaFlexibleContent\Http;

use Illuminate\Http\Request;
use Illuminate\Support\Collection;

trait ParsesFlexibleAttributes
{
Expand All @@ -22,7 +23,24 @@ trait ParsesFlexibleAttributes
protected function requestHasParsableFlexibleInputs(Request $request)
{
return in_array($request->method(), ['POST', 'PUT']) &&
is_string($request->input(FlexibleAttribute::REGISTER));
$this->hasParsableFlexibleInputs($request->input());
}

/**
* Check if the given array contains parsable flexible inputs
*
* @param array $request
* @return bool
*/
protected function hasParsableFlexibleInputs(array $array)
{
$inputs = collect($array)
->flatMap(function ($value, $key) {
return [$key => $value];
})
->toArray();
return isset($inputs[FlexibleAttribute::REGISTER]) &&
is_string($inputs[FlexibleAttribute::REGISTER]);
}

/**
Expand All @@ -31,12 +49,14 @@ protected function requestHasParsableFlexibleInputs(Request $request)
* @param \Illuminate\Http\Request $request
* @return array
*/
protected function getParsedFlexibleInputs(Request $request)
protected function getParsedFlexibleInputs(array $array)
{
$this->registerFlexibleFields($request->input(FlexibleAttribute::REGISTER));
$input = collect($array);

$this->registerFlexibleFields($input->get(FlexibleAttribute::REGISTER));

return array_reduce(array_keys($request->all()), function ($carry, $attribute) use ($request) {
$value = $request->input($attribute);
return array_reduce(array_keys($array), function ($carry, $attribute) use ($input) {
$value = $input->get($attribute);

if (! $this->isFlexibleAttribute($attribute, $value)) {
return $carry;
Expand Down
20 changes: 0 additions & 20 deletions webpack.mix.js.dist

This file was deleted.

Loading