Skip to content

Commit b6f73b6

Browse files
authored
fix: Support nova-flexible-content random key attribute format (#4) (#10)
* fix: support nova-flexible-content random key attribute format Updated regex patterns in extractPrefixFromAttribute() and extractBaseAttribute() to handle random alphanumeric keys like 'cSkn6uKpVHMkMLmI__' instead of just numeric index patterns like 'overlay_items__0__' Added Pattern 3: ^([a-zA-Z0-9]+__) for random key format * docs: update changelog and version for v1.0.11
1 parent c83d55d commit b6f73b6

6 files changed

Lines changed: 64 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All notable changes to `nova-dependency-container` will be documented in this file.
44

5+
## [1.0.11] - 2025-11-25
6+
7+
### Fixed
8+
- Fixed regex patterns to support nova-flexible-content's random key attribute format
9+
- The package was only matching numeric index patterns like `overlay_items__0__` but not random keys like `cSkn6uKpVHMkMLmI__`
10+
11+
### Changed
12+
- Updated `extractPrefixFromAttribute()` to support random key format: `^([a-zA-Z0-9]+__)`
13+
- Updated `extractBaseAttribute()` to extract field names from random key prefixed attributes
14+
15+
### Technical
16+
- nova-flexible-content uses random alphanumeric keys instead of numeric indices
17+
- Example: `cSkn6uKpVHMkMLmI__type` instead of `overlay_items__0__type`
18+
519
## [1.0.10] - 2025-11-25
620

721
### Fixed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iamgerwin/nova-dependency-container",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"description": "A Laravel Nova 4 and 5 field container allowing to depend on other fields values",
55
"keywords": [
66
"laravel",

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/flexible-field-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ This ensures that changing a field in Overlay Item #1 doesn't affect the depende
168168

169169
## Version History
170170

171+
- **1.0.11**: Fixed regex patterns to support nova-flexible-content's random key format
171172
- **1.0.10**: Fixed FieldServiceProvider not registering assets with Nova
172173
- **1.0.9**: Added debug logging to diagnose Flexible field issues
173174
- **1.0.8**: Fixed missing compiled assets in package distribution

resources/js/components/DetailField.vue

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,19 @@ export default {
253253
},
254254
255255
/**
256-
* Extract the prefix (e.g., "overlay_items__0__") from a full attribute.
256+
* Extract the prefix from a full attribute.
257+
* Supports multiple formats:
258+
* - "overlay_items__0__field_name" -> "overlay_items__0__"
259+
* - "overlay_items[0][field_name]" -> "overlay_items[0]["
260+
* - "cSkn6uKpVHMkMLmI__field_name" -> "cSkn6uKpVHMkMLmI__" (random key format)
257261
*/
258262
extractPrefixFromAttribute(attribute) {
259263
if (!attribute) return null;
260264
261-
// Pattern 1: Double underscore format (e.g., "overlay_items__0__field_name")
262-
const underscoreMatch = attribute.match(/^(.+__\d+__)/);
263-
if (underscoreMatch) {
264-
return underscoreMatch[1];
265+
// Pattern 1: Double underscore with numeric index (e.g., "overlay_items__0__field_name")
266+
const numericUnderscoreMatch = attribute.match(/^(.+__\d+__)/);
267+
if (numericUnderscoreMatch) {
268+
return numericUnderscoreMatch[1];
265269
}
266270
267271
// Pattern 2: Bracket format (e.g., "overlay_items[0][field_name]")
@@ -270,6 +274,12 @@ export default {
270274
return bracketMatch[1];
271275
}
272276
277+
// Pattern 3: Random key format (e.g., "cSkn6uKpVHMkMLmI__field_name" or just "cSkn6uKpVHMkMLmI__")
278+
const randomKeyMatch = attribute.match(/^([a-zA-Z0-9]+__)/);
279+
if (randomKeyMatch) {
280+
return randomKeyMatch[1];
281+
}
282+
273283
return null;
274284
},
275285

resources/js/components/FormField.vue

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,20 @@ export default {
252252
},
253253
254254
/**
255-
* Extract the prefix (e.g., "overlay_items__0__") from a full attribute.
255+
* Extract the prefix from a full attribute.
256+
* Supports multiple formats:
257+
* - "overlay_items__0__field_name" -> "overlay_items__0__"
258+
* - "overlay_items[0][field_name]" -> "overlay_items[0]["
259+
* - "cSkn6uKpVHMkMLmI__field_name" -> "cSkn6uKpVHMkMLmI__" (random key format)
260+
* - "cSkn6uKpVHMkMLmI__" -> "cSkn6uKpVHMkMLmI__" (prefix only)
256261
*/
257262
extractPrefixFromAttribute(attribute) {
258263
if (!attribute) return null;
259264
260-
// Pattern 1: Double underscore format (e.g., "overlay_items__0__field_name")
261-
const underscoreMatch = attribute.match(/^(.+__\d+__)/);
262-
if (underscoreMatch) {
263-
return underscoreMatch[1];
265+
// Pattern 1: Double underscore with numeric index (e.g., "overlay_items__0__field_name")
266+
const numericUnderscoreMatch = attribute.match(/^(.+__\d+__)/);
267+
if (numericUnderscoreMatch) {
268+
return numericUnderscoreMatch[1];
264269
}
265270
266271
// Pattern 2: Bracket format (e.g., "overlay_items[0][field_name]")
@@ -269,21 +274,30 @@ export default {
269274
return bracketMatch[1];
270275
}
271276
277+
// Pattern 3: Random key format (e.g., "cSkn6uKpVHMkMLmI__field_name" or just "cSkn6uKpVHMkMLmI__")
278+
// This handles nova-flexible-content's random key format
279+
const randomKeyMatch = attribute.match(/^([a-zA-Z0-9]+__)/);
280+
if (randomKeyMatch) {
281+
return randomKeyMatch[1];
282+
}
283+
272284
return null;
273285
},
274286
275287
/**
276288
* Extract the base attribute name from a potentially prefixed Flexible field attribute.
277-
* e.g., "overlay_items__0__type" -> "type"
278-
* "overlay_items[0][type]" -> "type"
289+
* Supports multiple formats:
290+
* - "overlay_items__0__type" -> "type"
291+
* - "overlay_items[0][type]" -> "type"
292+
* - "cSkn6uKpVHMkMLmI__type" -> "type" (random key format)
279293
*/
280294
extractBaseAttribute(attribute) {
281295
if (!attribute) return null;
282296
283-
// Pattern 1: Double underscore format (e.g., "overlay_items__0__field_name")
284-
const underscoreMatch = attribute.match(/^.+__\d+__(.+)$/);
285-
if (underscoreMatch) {
286-
return underscoreMatch[1];
297+
// Pattern 1: Double underscore with numeric index (e.g., "overlay_items__0__field_name")
298+
const numericUnderscoreMatch = attribute.match(/^.+__\d+__(.+)$/);
299+
if (numericUnderscoreMatch) {
300+
return numericUnderscoreMatch[1];
287301
}
288302
289303
// Pattern 2: Bracket format (e.g., "overlay_items[0][field_name]")
@@ -292,6 +306,13 @@ export default {
292306
return bracketMatch[1];
293307
}
294308
309+
// Pattern 3: Random key format (e.g., "cSkn6uKpVHMkMLmI__type")
310+
// This handles nova-flexible-content's random key format
311+
const randomKeyMatch = attribute.match(/^[a-zA-Z0-9]+__(.+)$/);
312+
if (randomKeyMatch) {
313+
return randomKeyMatch[1];
314+
}
315+
295316
return attribute;
296317
},
297318

0 commit comments

Comments
 (0)