diff --git a/CHANGELOG.md b/CHANGELOG.md index 71bae7e..35679fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All notable changes to `nova-dependency-container` will be documented in this file. +## [1.0.14] - 2025-11-25 + +### Fixed +- Fixed dependent field values not being saved on form submission (Vue 3 ref pattern) +- The previous fix in v1.0.13 used dynamic string refs which don't work reliably in Vue 3 v-for loops + +### Changed +- Switched from dynamic string refs (`:ref="'field-' + field.attribute"`) to Vue 3 function refs (`:ref="(el) => setFieldRef(field.attribute, el)"`) +- Added `fieldRefs` data property to store child field component references +- Added `setFieldRef()` method to properly collect and manage child component refs +- Updated `fill()` method to use the new `fieldRefs` object for accessing child components +- Added cleanup for `fieldRefs` in `beforeUnmount` lifecycle hook + +### Technical +- Vue 3 requires function refs when using dynamic ref names in v-for loops +- Dynamic string refs like `:ref="'field-' + x"` create arrays but are unreliable to access via `$refs[key]` +- Function refs `:ref="(el) => refs[key] = el"` provide direct access to component instances + ## [1.0.13] - 2025-11-25 ### Fixed diff --git a/dist/js/field.js b/dist/js/field.js index 66c7c90..f14ca75 100644 --- a/dist/js/field.js +++ b/dist/js/field.js @@ -1 +1 @@ -(()=>{"use strict";var e,t={72:(e,t,n)=>{var r,i=function(){return void 0===r&&(r=Boolean(window&&document&&document.all&&!window.atob)),r},o=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),a=[];function l(e){for(var t=-1,n=0;n{n.d(t,{A:()=>o});var r=n(314),i=n.n(r)()(function(e){return e[1]});i.push([e.id,".nova-dependency-container[data-v-4a25702c]{transition:all .3s ease}",""]);const o=i},254:(e,t,n)=>{n.d(t,{A:()=>o});var r=n(314),i=n.n(r)()(function(e){return e[1]});i.push([e.id,".nova-dependency-container[data-v-f5f08646]{transition:all .3s ease}",""]);const o=i},262:(e,t)=>{t.A=(e,t)=>{const n=e.__vccOpts||e;for(const[e,r]of t)n[e]=r;return n}},314:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=e(t);return t[2]?"@media ".concat(t[2]," {").concat(n,"}"):n}).join("")},t.i=function(e,n,r){"string"==typeof e&&(e=[[null,e,""]]);var i={};if(r)for(var o=0;o{},994:(e,t,n)=>{const r=Vue;const i={props:["resourceName","field"]};var o=n(262);const a=(0,o.A)(i,[["render",function(e,t,n,i,o,a){return(0,r.openBlock)(),(0,r.createElementBlock)("div")}]]);function l(e){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l(e)}function c(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,o,a,l=[],c=!0,s=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=o.call(n)).done)&&(l.push(r.value),l.length!==t);c=!0);}catch(e){s=!0,i=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw i}}return l}}(e,t)||d(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=d(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw o}}}}function d(e,t){if(e){if("string"==typeof e)return u(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(e,t):void 0}}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n0;){var n;if(e.fields&&Array.isArray(e.fields))return e.fields;if(null!==(n=e.$refs)&&void 0!==n&&n.fields&&Array.isArray(e.$refs.fields))return e.$refs.fields.map(function(e){return e.field||e});e=e.$parent}return[]},extractPrefixFromAttribute:function(e){if(!e)return null;var t=e.match(/^(.+__\d+__)/);if(t)return t[1];var n=e.match(/^(.+\[\d+\]\[)/);if(n)return n[1];var r=e.match(/^([a-zA-Z0-9]+__)/);return r?r[1]:null},getFlexibleAttributeFormats:function(e,t){var n=[],r=e.match(/^(.+)__(\d+)__$/),i=e.match(/^(.+)\[(\d+)\]\[$/);if(r){var o=c(r,3),a=o[1],l=o[2];n.push("".concat(a,"[").concat(l,"][").concat(t,"]")),n.push("".concat(a,"_").concat(l,"_").concat(t))}if(i){var s=c(i,3),d=s[1],u=s[2];n.push("".concat(d,"__").concat(u,"__").concat(t)),n.push("".concat(d,"_").concat(u,"_").concat(t))}return n},isEmpty:function(e){return null==e||""===e||Array.isArray(e)&&0===e.length||"object"===l(e)&&0===Object.keys(e).length}}};var h=n(72),v=n.n(h),p=n(254),y={insert:"head",singleton:!1};v()(p.A,y);p.A.locals;const b=(0,o.A)(f,[["render",function(e,t,n,i,o,a){return(0,r.withDirectives)(((0,r.openBlock)(),(0,r.createElementBlock)("div",{class:(0,r.normalizeClass)(a.containerClasses)},[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(n.field.fields,function(e,t){return(0,r.openBlock)(),(0,r.createBlock)((0,r.resolveDynamicComponent)("detail-".concat(e.component)),{key:t,"resource-name":n.resourceName,"resource-id":n.resourceId,field:e},null,8,["resource-name","resource-id","field"])}),128))],2)),[[r.vShow,o.isVisible]])}],["__scopeId","data-v-f5f08646"]]);const m=LaravelNova;function x(e){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},x(e)}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,o,a,l=[],c=!0,s=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=o.call(n)).done)&&(l.push(r.value),l.length!==t);c=!0);}catch(e){s=!0,i=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw i}}return l}}(e,t)||A(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function C(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=A(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw o}}}}function A(e,t){if(e){if("string"==typeof e)return F(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?F(e,t):void 0}}function F(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n1)return n;n=n.parentElement,r++}return(null===(e=this.$el)||void 0===e?void 0:e.closest("form"))||(null===(t=this.$el)||void 0===t?void 0:t.closest("[data-field-wrapper]"))||document.body},handleDOMChange:function(e){var t=e.target,n=t.name||t.id||"",r="checkbox"===t.type?t.checked:t.value;if(console.log("[NovaDependencyContainer] DOM change detected:",{name:n,value:r}),n){var i=this.extractPrefixFromAttribute(n);if(!this.cachedContextPrefix||!i||i===this.cachedContextPrefix){var o=this.extractBaseAttribute(n);this.field.dependencies.some(function(e){return e.field===o})&&(console.log("[NovaDependencyContainer] Relevant field changed via DOM:",o,"=",r),this.dependentFieldValues[n]=r,this.dependentFieldValues[o]=r,this.checkDependencies())}}},loadInitialValuesFromDOM:function(){if(this.field.dependencies){console.log("[NovaDependencyContainer] Loading initial values from DOM");var e,t=C(this.field.dependencies);try{for(t.s();!(e=t.n()).done;)for(var n=e.value.field,r=this.cachedContextPrefix?"".concat(this.cachedContextPrefix).concat(n):n,i=['[name="'.concat(r,'"]'),'[name="'.concat(n,'"]'),'[id="'.concat(r,'"]'),'[id="'.concat(n,'"]'),'[name$="__'.concat(n,'"]'),'[name$="['.concat(n,']"]')],o=0,a=i;o0;){var r;if(null!==(r=t.$refs)&&void 0!==r&&r.fields&&Array.isArray(t.$refs.fields))return t.$refs.fields;if(t.fields&&Array.isArray(t.fields))return t.fields.map(function(e){return{field:e}});t=t.$parent}return[]},getFlexibleAttributeFormats:function(e,t){var n=[],r=e.match(/^(.+)__(\d+)__$/),i=e.match(/^(.+)\[(\d+)\]\[$/);if(r){var o=g(r,3),a=o[1],l=o[2];n.push("".concat(a,"[").concat(l,"][").concat(t,"]")),n.push("".concat(a,"_").concat(l,"_").concat(t))}if(i){var c=g(i,3),s=c[1],d=c[2];n.push("".concat(s,"__").concat(d,"__").concat(t)),n.push("".concat(s,"_").concat(d,"_").concat(t))}return n},isEmpty:function(e){return null==e||""===e||Array.isArray(e)&&0===e.length||"object"===x(e)&&0===Object.keys(e).length},fill:function(e){var t=this;console.log("[NovaDependencyContainer] fill() called, isVisible:",this.isVisible),this.isVisible?this.field.fields&&this.field.fields.forEach(function(n){var r="field-".concat(n.attribute),i=t.$refs[r];Array.isArray(i)&&(i=i[0]),console.log("[NovaDependencyContainer] Filling field:",n.attribute,"component:",i),i&&"function"==typeof i.fill?(i.fill(e),console.log("[NovaDependencyContainer] Field filled:",n.attribute)):console.log("[NovaDependencyContainer] Could not fill field:",n.attribute,"ref not found or no fill method")}):console.log("[NovaDependencyContainer] Not visible, skipping fill")}},beforeUnmount:function(){var e=this;Nova.$off("field-changed",this.handleFieldChanged),this.watchedElements&&this.watchedElements.forEach(function(t){t.removeEventListener("change",e.handleDOMChange),t.removeEventListener("input",e.handleDOMChange)}),this.mutationObserver&&this.mutationObserver.disconnect()}};var O=n(236),_={insert:"head",singleton:!1};v()(O.A,_);O.A.locals;const P=(0,o.A)(D,[["render",function(e,t,n,i,o,a){return(0,r.withDirectives)(((0,r.openBlock)(),(0,r.createElementBlock)("div",{class:(0,r.normalizeClass)(a.containerClasses)},[((0,r.openBlock)(!0),(0,r.createElementBlock)(r.Fragment,null,(0,r.renderList)(n.field.fields,function(i,o){return(0,r.openBlock)(),(0,r.createBlock)((0,r.resolveDynamicComponent)("form-".concat(i.component)),{key:i.attribute||o,ref_for:!0,ref:"field-"+i.attribute,"resource-name":n.resourceName,"resource-id":n.resourceId,field:i,errors:n.errors,"show-help-text":n.showHelpText,mode:n.mode,"via-resource":n.viaResource,"via-resource-id":n.viaResourceId,"via-relationship":n.viaRelationship,onFieldChanged:a.handleFieldChanged,onFileDeleted:t[0]||(t[0]=function(t){return e.$emit("file-deleted")}),onFileUploadStarted:t[1]||(t[1]=function(t){return e.$emit("file-upload-started")}),onFileUploadFinished:t[2]||(t[2]=function(t){return e.$emit("file-upload-finished")})},null,40,["resource-name","resource-id","field","errors","show-help-text","mode","via-resource","via-resource-id","via-relationship","onFieldChanged"])}),128))],2)),[[r.vShow,o.isVisible]])}],["__scopeId","data-v-4a25702c"]]);Nova.booting(function(e,t){e.component("index-nova-dependency-container",a),e.component("detail-nova-dependency-container",b),e.component("form-nova-dependency-container",P)})}},n={};function r(e){var i=n[e];if(void 0!==i)return i.exports;var o=n[e]={id:e,exports:{}};return t[e](o,o.exports,r),o.exports}r.m=t,e=[],r.O=(t,n,i,o)=>{if(!n){var a=1/0;for(d=0;d=o)&&Object.keys(r.O).every(e=>r.O[e](n[c]))?n.splice(c--,1):(l=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[n,i,o]},r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={222:0,101:0};r.O.j=t=>0===e[t];var t=(t,n)=>{var i,o,[a,l,c]=n,s=0;if(a.some(t=>0!==e[t])){for(i in l)r.o(l,i)&&(r.m[i]=l[i]);if(c)var d=c(r)}for(t&&t(n);sr(994));var i=r.O(void 0,[101],()=>r(835));i=r.O(i)})(); \ No newline at end of file +(()=>{"use strict";var e,t={72:(e,t,n)=>{var i,r=function(){return void 0===i&&(i=Boolean(window&&document&&document.all&&!window.atob)),i},o=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),a=[];function l(e){for(var t=-1,n=0;n{n.d(t,{A:()=>o});var i=n(314),r=n.n(i)()(function(e){return e[1]});r.push([e.id,".nova-dependency-container[data-v-f5f08646]{transition:all .3s ease}",""]);const o=r},262:(e,t)=>{t.A=(e,t)=>{const n=e.__vccOpts||e;for(const[e,i]of t)n[e]=i;return n}},314:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n=e(t);return t[2]?"@media ".concat(t[2]," {").concat(n,"}"):n}).join("")},t.i=function(e,n,i){"string"==typeof e&&(e=[[null,e,""]]);var r={};if(i)for(var o=0;o{n.d(t,{A:()=>o});var i=n(314),r=n.n(i)()(function(e){return e[1]});r.push([e.id,".nova-dependency-container[data-v-076f938a]{transition:all .3s ease}",""]);const o=r},835:()=>{},921:(e,t,n)=>{const i=Vue;const r={props:["resourceName","field"]};var o=n(262);const a=(0,o.A)(r,[["render",function(e,t,n,r,o,a){return(0,i.openBlock)(),(0,i.createElementBlock)("div")}]]);function l(e){return l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},l(e)}function c(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var i,r,o,a,l=[],c=!0,s=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(i=o.call(n)).done)&&(l.push(i.value),l.length!==t);c=!0);}catch(e){s=!0,r=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw r}}return l}}(e,t)||d(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=d(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw o}}}}function d(e,t){if(e){if("string"==typeof e)return u(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(e,t):void 0}}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n0;){var n;if(e.fields&&Array.isArray(e.fields))return e.fields;if(null!==(n=e.$refs)&&void 0!==n&&n.fields&&Array.isArray(e.$refs.fields))return e.$refs.fields.map(function(e){return e.field||e});e=e.$parent}return[]},extractPrefixFromAttribute:function(e){if(!e)return null;var t=e.match(/^(.+__\d+__)/);if(t)return t[1];var n=e.match(/^(.+\[\d+\]\[)/);if(n)return n[1];var i=e.match(/^([a-zA-Z0-9]+__)/);return i?i[1]:null},getFlexibleAttributeFormats:function(e,t){var n=[],i=e.match(/^(.+)__(\d+)__$/),r=e.match(/^(.+)\[(\d+)\]\[$/);if(i){var o=c(i,3),a=o[1],l=o[2];n.push("".concat(a,"[").concat(l,"][").concat(t,"]")),n.push("".concat(a,"_").concat(l,"_").concat(t))}if(r){var s=c(r,3),d=s[1],u=s[2];n.push("".concat(d,"__").concat(u,"__").concat(t)),n.push("".concat(d,"_").concat(u,"_").concat(t))}return n},isEmpty:function(e){return null==e||""===e||Array.isArray(e)&&0===e.length||"object"===l(e)&&0===Object.keys(e).length}}};var h=n(72),v=n.n(h),p=n(254),y={insert:"head",singleton:!1};v()(p.A,y);p.A.locals;const b=(0,o.A)(f,[["render",function(e,t,n,r,o,a){return(0,i.withDirectives)(((0,i.openBlock)(),(0,i.createElementBlock)("div",{class:(0,i.normalizeClass)(a.containerClasses)},[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(n.field.fields,function(e,t){return(0,i.openBlock)(),(0,i.createBlock)((0,i.resolveDynamicComponent)("detail-".concat(e.component)),{key:t,"resource-name":n.resourceName,"resource-id":n.resourceId,field:e},null,8,["resource-name","resource-id","field"])}),128))],2)),[[i.vShow,o.isVisible]])}],["__scopeId","data-v-f5f08646"]]);const m=LaravelNova;function x(e){return x="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},x(e)}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var i,r,o,a,l=[],c=!0,s=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(i=o.call(n)).done)&&(l.push(i.value),l.length!==t);c=!0);}catch(e){s=!0,r=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw r}}return l}}(e,t)||A(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function C(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=A(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){l=!0,o=e},f:function(){try{a||null==n.return||n.return()}finally{if(l)throw o}}}}function A(e,t){if(e){if("string"==typeof e)return F(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?F(e,t):void 0}}function F(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n1)return n;n=n.parentElement,i++}return(null===(e=this.$el)||void 0===e?void 0:e.closest("form"))||(null===(t=this.$el)||void 0===t?void 0:t.closest("[data-field-wrapper]"))||document.body},handleDOMChange:function(e){var t=e.target,n=t.name||t.id||"",i="checkbox"===t.type?t.checked:t.value;if(console.log("[NovaDependencyContainer] DOM change detected:",{name:n,value:i}),n){var r=this.extractPrefixFromAttribute(n);if(!this.cachedContextPrefix||!r||r===this.cachedContextPrefix){var o=this.extractBaseAttribute(n);this.field.dependencies.some(function(e){return e.field===o})&&(console.log("[NovaDependencyContainer] Relevant field changed via DOM:",o,"=",i),this.dependentFieldValues[n]=i,this.dependentFieldValues[o]=i,this.checkDependencies())}}},loadInitialValuesFromDOM:function(){if(this.field.dependencies){console.log("[NovaDependencyContainer] Loading initial values from DOM");var e,t=C(this.field.dependencies);try{for(t.s();!(e=t.n()).done;)for(var n=e.value.field,i=this.cachedContextPrefix?"".concat(this.cachedContextPrefix).concat(n):n,r=['[name="'.concat(i,'"]'),'[name="'.concat(n,'"]'),'[id="'.concat(i,'"]'),'[id="'.concat(n,'"]'),'[name$="__'.concat(n,'"]'),'[name$="['.concat(n,']"]')],o=0,a=r;o0;){var i;if(null!==(i=t.$refs)&&void 0!==i&&i.fields&&Array.isArray(t.$refs.fields))return t.$refs.fields;if(t.fields&&Array.isArray(t.fields))return t.fields.map(function(e){return{field:e}});t=t.$parent}return[]},getFlexibleAttributeFormats:function(e,t){var n=[],i=e.match(/^(.+)__(\d+)__$/),r=e.match(/^(.+)\[(\d+)\]\[$/);if(i){var o=g(i,3),a=o[1],l=o[2];n.push("".concat(a,"[").concat(l,"][").concat(t,"]")),n.push("".concat(a,"_").concat(l,"_").concat(t))}if(r){var c=g(r,3),s=c[1],d=c[2];n.push("".concat(s,"__").concat(d,"__").concat(t)),n.push("".concat(s,"_").concat(d,"_").concat(t))}return n},isEmpty:function(e){return null==e||""===e||Array.isArray(e)&&0===e.length||"object"===x(e)&&0===Object.keys(e).length},fill:function(e){var t=this;console.log("[NovaDependencyContainer] fill() called, isVisible:",this.isVisible),console.log("[NovaDependencyContainer] Available fieldRefs:",Object.keys(this.fieldRefs)),this.isVisible?this.field.fields&&this.field.fields.forEach(function(n){var i=t.fieldRefs[n.attribute];console.log("[NovaDependencyContainer] Filling field:",n.attribute,"component:",i?"found":"not found"),i&&"function"==typeof i.fill?(i.fill(e),console.log("[NovaDependencyContainer] Field filled successfully:",n.attribute)):console.warn("[NovaDependencyContainer] Could not fill field:",n.attribute,"ref not found or no fill method")}):console.log("[NovaDependencyContainer] Not visible, skipping fill")}},beforeUnmount:function(){var e=this;Nova.$off("field-changed",this.handleFieldChanged),this.watchedElements&&this.watchedElements.forEach(function(t){t.removeEventListener("change",e.handleDOMChange),t.removeEventListener("input",e.handleDOMChange)}),this.mutationObserver&&this.mutationObserver.disconnect(),this.fieldRefs={}}};var O=n(352),_={insert:"head",singleton:!1};v()(O.A,_);O.A.locals;const P=(0,o.A)(D,[["render",function(e,t,n,r,o,a){return(0,i.withDirectives)(((0,i.openBlock)(),(0,i.createElementBlock)("div",{class:(0,i.normalizeClass)(a.containerClasses)},[((0,i.openBlock)(!0),(0,i.createElementBlock)(i.Fragment,null,(0,i.renderList)(n.field.fields,function(r,o){return(0,i.openBlock)(),(0,i.createBlock)((0,i.resolveDynamicComponent)("form-".concat(r.component)),{key:r.attribute||o,ref_for:!0,ref:function(e){return a.setFieldRef(r.attribute,e)},"resource-name":n.resourceName,"resource-id":n.resourceId,field:r,errors:n.errors,"show-help-text":n.showHelpText,mode:n.mode,"via-resource":n.viaResource,"via-resource-id":n.viaResourceId,"via-relationship":n.viaRelationship,onFieldChanged:a.handleFieldChanged,onFileDeleted:t[0]||(t[0]=function(t){return e.$emit("file-deleted")}),onFileUploadStarted:t[1]||(t[1]=function(t){return e.$emit("file-upload-started")}),onFileUploadFinished:t[2]||(t[2]=function(t){return e.$emit("file-upload-finished")})},null,40,["resource-name","resource-id","field","errors","show-help-text","mode","via-resource","via-resource-id","via-relationship","onFieldChanged"])}),128))],2)),[[i.vShow,o.isVisible]])}],["__scopeId","data-v-076f938a"]]);Nova.booting(function(e,t){e.component("index-nova-dependency-container",a),e.component("detail-nova-dependency-container",b),e.component("form-nova-dependency-container",P)})}},n={};function i(e){var r=n[e];if(void 0!==r)return r.exports;var o=n[e]={id:e,exports:{}};return t[e](o,o.exports,i),o.exports}i.m=t,e=[],i.O=(t,n,r,o)=>{if(!n){var a=1/0;for(d=0;d=o)&&Object.keys(i.O).every(e=>i.O[e](n[c]))?n.splice(c--,1):(l=!1,o0&&e[d-1][2]>o;d--)e[d]=e[d-1];e[d]=[n,r,o]},i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={222:0,101:0};i.O.j=t=>0===e[t];var t=(t,n)=>{var r,o,[a,l,c]=n,s=0;if(a.some(t=>0!==e[t])){for(r in l)i.o(l,r)&&(i.m[r]=l[r]);if(c)var d=c(i)}for(t&&t(n);si(921));var r=i.O(void 0,[101],()=>i(835));r=i.O(r)})(); \ No newline at end of file diff --git a/resources/js/components/FormField.vue b/resources/js/components/FormField.vue index 7e9a67c..adad68b 100644 --- a/resources/js/components/FormField.vue +++ b/resources/js/components/FormField.vue @@ -3,7 +3,7 @@ { - const refKey = `field-${field.attribute}`; - let fieldComponent = this.$refs[refKey]; - - // In Vue 3, refs in v-for are stored as arrays - if (Array.isArray(fieldComponent)) { - fieldComponent = fieldComponent[0]; - } + // Use Vue 3 function refs stored in fieldRefs object + const fieldComponent = this.fieldRefs[field.attribute]; - console.log('[NovaDependencyContainer] Filling field:', field.attribute, 'component:', fieldComponent); + console.log('[NovaDependencyContainer] Filling field:', field.attribute, 'component:', fieldComponent ? 'found' : 'not found'); if (fieldComponent && typeof fieldComponent.fill === 'function') { fieldComponent.fill(formData); - console.log('[NovaDependencyContainer] Field filled:', field.attribute); + console.log('[NovaDependencyContainer] Field filled successfully:', field.attribute); } else { - console.log('[NovaDependencyContainer] Could not fill field:', field.attribute, 'ref not found or no fill method'); + console.warn('[NovaDependencyContainer] Could not fill field:', field.attribute, 'ref not found or no fill method'); } }); } @@ -736,6 +745,9 @@ export default { if (this.mutationObserver) { this.mutationObserver.disconnect(); } + + // Clean up field refs + this.fieldRefs = {}; }, };