Skip to content

Commit 1352a4c

Browse files
committed
wip
1 parent 0697c4c commit 1352a4c

File tree

7 files changed

+56
-40
lines changed

7 files changed

+56
-40
lines changed

src/app/View/Components/Dataform.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public function __construct(
3333
public string $controller,
3434
private string $id = 'backpack-form-',
3535
public string $name = '',
36-
public string $operation = 'create',
37-
public ?string $action = null,
38-
public string $method = 'post',
36+
public string $formOperation = 'create',
37+
public ?string $formAction = null,
38+
public string $formMethod = 'post',
3939
public bool $hasUploadFields = false,
4040
public $entry = null,
4141
public ?Closure $setup = null,
@@ -44,25 +44,25 @@ public function __construct(
4444
// Get CRUD panel instance from the controller
4545
CrudManager::setActiveController($controller);
4646

47-
$this->crud = CrudManager::setupCrudPanel($controller, $operation);
47+
$this->crud = CrudManager::setupCrudPanel($controller, $this->formOperation);
4848

49-
if ($this->crud->getOperation() !== $operation) {
50-
$this->crud->setOperation($operation);
49+
if ($this->crud->getOperation() !== $this->formOperation) {
50+
$this->crud->setOperation($this->formOperation);
5151
}
5252

5353
$this->crud->setAutoFocusOnFirstField($this->focusOnFirstField);
5454

55-
if ($this->entry && $this->operation === 'update') {
56-
$this->action = $action ?? url($this->crud->route.'/'.$this->entry->getKey());
57-
$this->method = 'put';
55+
if ($this->entry && $this->formOperation === 'update') {
56+
$this->formAction = $formAction ?? url($this->crud->route.'/'.$this->entry->getKey());
57+
$this->formMethod = 'put';
5858
$this->crud->entry = $this->entry;
5959
$this->crud->setOperationSetting('fields', $this->crud->getUpdateFields());
6060
} else {
61-
$this->action = $action ?? url($this->crud->route);
61+
$this->formAction = $formAction ?? url($this->crud->route);
6262
}
6363

64-
$this->hasUploadFields = $this->crud->hasUploadFields($operation, $this->entry?->getKey());
65-
$this->id = $id.md5($this->action.$this->operation.$this->method.$this->controller);
64+
$this->hasUploadFields = $this->crud->hasUploadFields($this->formOperation, $this->entry?->getKey());
65+
$this->id = $id.md5($this->formAction.$this->formOperation.$this->formMethod.$this->controller);
6666

6767
if ($this->setup) {
6868
$parentEntry = $this->getParentCrudEntry();
@@ -105,9 +105,9 @@ public function render()
105105
'saveAction' => $this->crud->getSaveAction(),
106106
'id' => $this->id,
107107
'name' => $this->name,
108-
'operation' => $this->operation,
109-
'action' => $this->action,
110-
'method' => $this->method,
108+
'formOperation' => $this->formOperation,
109+
'formAction' => $this->formAction,
110+
'formMethod' => $this->formMethod,
111111
'hasUploadFields' => $this->hasUploadFields,
112112
'entry' => $this->entry,
113113
]);

src/app/View/Components/DataformModal.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ public function __construct(
2222
public string $controller,
2323
public ?string $route = null,
2424
public string $id = 'backpack-form',
25-
public string $operation = 'create',
25+
public string $formOperation = 'create',
2626
public string $name = '',
27-
public string $formRouteOperation = 'create',
28-
public ?string $action = null,
29-
public string $method = 'post',
27+
public string $formUrl = 'create',
28+
public ?string $formAction = null,
29+
public string $formMethod = 'post',
3030
public bool $hasUploadFields = false,
3131
public $entry = null,
3232
public ?Closure $setup = null,
@@ -38,15 +38,16 @@ public function __construct(
3838
// If route is not provided (e.g., when rendering via AJAX), get it from CRUD panel
3939
if ($this->route === null) {
4040
\Backpack\CRUD\CrudManager::setActiveController($controller);
41-
$tempCrud = \Backpack\CRUD\CrudManager::setupCrudPanel($controller, $operation);
41+
$tempCrud = \Backpack\CRUD\CrudManager::setupCrudPanel($controller, $this->formOperation);
4242
$this->route = $tempCrud->route;
4343
\Backpack\CRUD\CrudManager::unsetActiveController();
4444
}
4545

46-
$this->action = $this->action ?? url($this->route);
46+
// keep backwards compatible behavior for resolving route when not provided
47+
$this->formAction = $this->formAction ?? url($this->route);
4748

4849
// Generate the SAME hashed form ID that the Dataform component uses
49-
$this->hashedFormId = $this->id.md5($action.$this->operation.'post'.$this->controller);
50+
$this->hashedFormId = $this->id.md5($this->formAction.$this->formOperation.'post'.$this->controller);
5051

5152
// Cache the setup closure if provided (for retrieval during AJAX request)
5253
if ($this->setup instanceof \Closure) {
@@ -56,9 +57,9 @@ public function __construct(
5657
// DO NOT call parent::__construct() because we don't want to initialize
5758
// the CRUD panel on page load - the form will be loaded via AJAX
5859

59-
if ($this->entry && $this->operation === 'update') {
60+
if ($this->entry && $this->formOperation === 'update') {
6061
// Use the resolved action (base route) to build the edit URL for the entry
61-
$this->formRouteOperation = url($this->action.'/'.$this->entry->getKey().'/edit');
62+
$this->formUrl = url($this->formAction.'/'.$this->entry->getKey().'/edit');
6263
}
6364
}
6465

@@ -68,8 +69,8 @@ public function __construct(
6869
protected function cacheSetupClosure(): void
6970
{
7071
// Create a temporary CRUD instance to apply and cache the setup
71-
\Backpack\CRUD\CrudManager::setActiveController($this->controller);
72-
$tempCrud = \Backpack\CRUD\CrudManager::setupCrudPanel($this->controller, $this->operation);
72+
\Backpack\CRUD\CrudManager::setActiveController($this->controller);
73+
$tempCrud = \Backpack\CRUD\CrudManager::setupCrudPanel($this->controller, $this->formOperation);
7374

7475
// Apply and cache the setup closure using the HASHED ID
7576
\Backpack\CRUD\app\Library\Support\DataformCache::applyAndStoreSetupClosure(
@@ -95,12 +96,12 @@ public function render()
9596
// The CRUD panel will be initialized when the AJAX request is made
9697
return view('crud::components.dataform.modal-form', [
9798
'id' => $this->id,
98-
'operation' => $this->operation,
99-
'formRouteOperation' => $this->formRouteOperation,
99+
'formOperation' => $this->formOperation,
100+
'formUrl' => $this->formUrl,
100101
'hasUploadFields' => $this->hasUploadFields,
101102
'refreshDatatable' => $this->refreshDatatable,
102-
'action' => $this->action,
103-
'method' => $this->method,
103+
'formAction' => $this->formAction,
104+
'formMethod' => $this->formMethod,
104105
'title' => $this->title,
105106
'classes' => $this->classes,
106107
'hashedFormId' => $this->hashedFormId,

src/resources/views/crud/components/dataform/common_js.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@verbatim
12
if (typeof window.initializeFieldsWithJavascript === 'undefined') {
23
window.initializeFieldsWithJavascript = function(container) {
34
var selector;

src/resources/views/crud/components/dataform/form.blade.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
@include('crud::inc.grouped_errors', ['id' => $id])
33

44
<form method="post"
5-
action="{{ $action }}"
5+
action="{{ $formAction }}"
66
id="{{ $id }}"
77
@if(!empty($name)) name="{{ $name }}" @endif
88
@if($hasUploadFields) enctype="multipart/form-data" @endif
99
>
1010
{!! csrf_field() !!}
11-
12-
@if($method !== 'post')
13-
@method($method)
11+
@if($formMethod !== 'post')
12+
@method($formMethod)
1413
@endif
1514
{{-- Include the form fields --}}
16-
@include('crud::form_content', ['fields' => $crud->fields(), 'action' => $operation, 'id' => $id])
15+
@include('crud::form_content', ['fields' => $crud->fields(), 'action' => $formOperation, 'id' => $id])
1716

1817
{{-- This makes sure that all field assets are loaded. --}}
1918
<div class="d-none" id="parentLoadedAssets">{{ json_encode(Basset::loaded()) }}</div>

src/resources/views/crud/components/dataform/form_content.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<input type="hidden" name="_http_referrer" value="{{ old('_http_referrer') ?? \URL::previous() ?? url($crud->route) }}">
1+
<input type="hidden" name="_http_referrer" value="{{ old('_http_referrer') ?? \URL::previous() ?? url($crud->route) }}">
22
<input type="hidden" name="_modal_form_id" value="{{ $id ?? 'crudForm' }}">
33

44
{{-- See if we're using tabs --}}
@@ -25,4 +25,4 @@
2525

2626
@push('before_scripts')
2727
@include('crud::inc.form_fields_script')
28-
@endpush
28+
@endpush

src/resources/views/crud/components/dataform/modal-form.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
</div>
1818
<div
1919
id="modal-form-container{{ md5($controller.$id) }}"
20-
data-form-load-route="{{ isset($formRouteOperation) ? (\Str::isUrl($formRouteOperation) ? $formRouteOperation : url($route . '/' . $formRouteOperation)) : '' }}"
21-
data-form-action="{{ $action }}"
22-
data-form-method="{{ $method }}"
20+
data-form-load-route="{{ isset($formUrl) ? (\Str::isUrl($formUrl) ? $formUrl : url($route . '/' . $formUrl)) : '' }}"
21+
data-form-action="{{ $formAction }}"
22+
data-form-method="{{ $formMethod }}"
2323
data-has-upload-fields="{{ $hasUploadFields ? 'true' : 'false' }}"
2424
data-refresh-datatable="{{ $refreshDatatable ? 'true' : 'false' }}"
2525
>

src/resources/views/crud/fields/color.blade.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{{-- html5 color input --}}
22
@php
33
$value = old_empty_or_null($field['name'], '') ?? $field['value'] ?? $field['default'] ?? '';
4+
// HTML5 color input requires a valid hex color format (#rrggbb)
5+
// If the value is empty or invalid, default to black (#000000)
6+
if (empty($value) || !preg_match('/^#[0-9a-f]{6}$/i', $value)) {
7+
$value = $field['default'] ?? '#000000';
8+
}
49
@endphp
510

611

@@ -59,6 +64,16 @@ function bpFieldInitColorElement(element) {
5964
let inputText = element[0];
6065
let inputColor = inputText.nextElementSibling.querySelector('input');
6166
67+
// Ensure color input has a valid value (HTML5 requires #rrggbb format)
68+
if (!inputColor.value || !inputColor.value.match(/^#[0-9a-f]{6}$/i)) {
69+
inputColor.value = '#000000';
70+
}
71+
72+
// Ensure text input matches color input
73+
if (!inputText.value || !inputText.value.match(/^#[0-9a-f]{6}$/i)) {
74+
inputText.value = inputColor.value;
75+
}
76+
6277
inputText.addEventListener('input', () => inputText.value = inputColor.value = '#' + inputText.value.replace(/[^\da-f]/gi, '').toLowerCase());
6378
inputColor.addEventListener('input', () => inputText.value = inputColor.value);
6479
}

0 commit comments

Comments
 (0)