verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
96 stars 72 forks source link

Formie Asset Bundle path returns a 404 on CP submission back-end on Craft Cloud #2157

Open jamesmacwhite opened 5 days ago

jamesmacwhite commented 5 days ago

Describe the bug

I've noticed this between Formie 1.x and Formie 3. Any date field on the CP submission view is represented as the database date/time string value, without the date picker.

Current field in Formie 1:

(Ignore LastPass it likes to get involved on most fields...)

image

Current field in Formie 3:

image

The data is correct, but from a human representation perspective, it would be nice if the submission view used the date picker in the locale set i.e. like Craft does with date fields on entries.

Steps to reproduce

  1. Create a date field on a form.
  2. Create a submission with a date field populated.
  3. View the submission in the CP backend.
  4. See the representation in the backend of the date field.

Form settings

N/A

Craft CMS version

5.5.3

Plugin version

3.0.12

Multi-site?

No response

Additional context

No response

engram-design commented 4 days ago

What's your exact field settings for this field? It shouldn't be showing that for any combination:

image

I actually think there might be a JS error that's preventing the date picker from kicking in. We populate the date picker component with a proper ISO-formatted date, but the date picker should kick in to format that visually. Can you confirm any JS errors?

jamesmacwhite commented 4 days ago

Ah interesting.

I'm wondering if it is because of using the date/time events to set additional formats e.g.

Event::on(Date::class,
            Date::EVENT_MODIFY_DATE_FORMAT,
            static function(ModifyDateTimeFormatEvent $event) {
                $event->dateFormat = 'd/m/Y';
            }
        );

        Event::on(Date::class,
            Date::EVENT_MODIFY_TIME_FORMAT,
            static function(ModifyDateTimeFormatEvent $event) {
                $event->timeFormat = 'g:i A';
            }
        );

        Event::on(Date::class,
            Date::EVENT_REGISTER_TIME_FORMAT_OPTIONS,
            static function(RegisterDateTimeFormatOpionsEvent $event) {
                $event->options[] = ['label' => '1:00 PM (g:i AM/PM)', 'value' => 'g:i A'];
            }
        );

I'll do some testing.

jamesmacwhite commented 4 days ago

Looks like it might be related to the AssetBundle throwing a 404 when viewing the submission backend, when checking the console.

https://craftcms.com/knowledge-base/cloud-plugin-development#asset-bundles

Craft Cloud which we run our staging and live environment on publishes all asset bundles at build/deploy through the CDN path.

There is note here: Publishing one-off or ad-hoc assets at runtime is not supported on Cloud.

Not sure if this is happening anywhere?

The AssetBundle paths that are throwing a 404:

https://cdn.craft.cloud/d10b9526-496f-4cd6-a8ff-319f00317266/builds/9d93248e-6e98-4911-95c8-5d3855780b98/cpresources/craft-web-assets-datepickeri18n-dist/datepicker-en-GB.js?v=1732318185

https://cdn.craft.cloud/d10b9526-496f-4cd6-a8ff-319f00317266/builds/9d93248e-6e98-4911-95c8-5d3855780b98/cpresources/verbb-formie-web-assets-frontend/dist/js/formie.js?v=1731753441

I can't see any 404 errors happening on the front-end interestingly though. The advanced date with Flatpickr is functioning on the front end, only on the CP backend does it appear to be failing due to the AssetBundle 404.

jamesmacwhite commented 4 days ago

Comparing the two, there appears to be some slight path variance on the front-end compared to the back-end:

Working paths on the front end:

https://cdn.craft.cloud/d10b9526-496f-4cd6-a8ff-319f00317266/builds/9d93248e-6e98-4911-95c8-5d3855780b98/cpresources/verbb-formie-web-assets-frontend-dist/js/fields/date-picker.js?v=1731753441
https://cdn.craft.cloud/d10b9526-496f-4cd6-a8ff-319f00317266/builds/9d93248e-6e98-4911-95c8-5d3855780b98/cpresources/verbb-formie-web-assets-frontend-dist/js/formie.js?v=1731753441

CP submission backend (404):

https://cdn.craft.cloud/d10b9526-496f-4cd6-a8ff-319f00317266/builds/9d93248e-6e98-4911-95c8-5d3855780b98/cpresources/craft-web-assets-datepickeri18n-dist/datepicker-en-GB.js?v=1732318185
https://cdn.craft.cloud/d10b9526-496f-4cd6-a8ff-319f00317266/builds/9d93248e-6e98-4911-95c8-5d3855780b98/cpresources/verbb-formie-web-assets-frontend/dist/js/formie.js?v=1731753441

The differences appear to be:

What do we think, Craft Cloud bug?

engram-design commented 4 days ago

Ah, so yes this is probably related to Craft Cloud and how they handle assets. I'll look into it further.

The formie.js file is going to try and lazy-load other JS in, but seeing as though that 404's, it can't do that. The datepicker-en-GB.js would be for Craft's date picker, not something we bundle with Formie.

jamesmacwhite commented 4 days ago

It will be for sure. All of the asset bundles are redirected to the CDN path during the build, interesting that it happens for the CP but not front-end which I guess is the better scenario.

Would you like me to raise a support case with Craft Cloud, happy to summarise the findings for further review?

engram-design commented 4 days ago

Yeah might be worthwhile, I'll investigate on my end!

jamesmacwhite commented 4 days ago

Thanks Josh, will do and I'll keep you updated.

timkelty commented 3 days ago

@engram-design @jamesmacwhite I've seen other reports of similar issues for Cloud. Pretty sure it is just more references to fix, like happened here.

I'll try and take a look today.

jamesmacwhite commented 3 days ago

Thanks @timkelty! Let me know if you anything to help test.

jamesmacwhite commented 3 days ago

I think I found the issue, it is indeed a path issue in the submission edit Twig template. I've made a PR to fix.

I don't know about the datepicker error though, as @engram-design mentioned, this is Craft's asset bundle.

engram-design commented 3 days ago

Appreciate the PR! To get this early, run composer require verbb/formie:"dev-craft-5 as 3.0.12".

jamesmacwhite commented 2 days ago

Confirming, resolved on our Craft Cloud environments.