twill: Edit form doesn't load

I’m following the documentation to add Twill (1.2.) on a fresh install (php ^7.1.3 & laravel 5.7.).

For now, I only set these env values on the .env:

MEDIA_LIBRARY_ENDPOINT_TYPE=local
MEDIA_LIBRARY_LOCAL_PATH=uploads/
FILE_LIBRARY_ENDPOINT_TYPE=local
FILE_LIBRARY_LOCAL_PATH=uploads/
MEDIA_LIBRARY_IMAGE_SERVICE=A17\Twill\Services\MediaLibrary\Local

And I setup the database to use sqlite3.

No problem with the installation, everything is going well. I’ve my administration credentials but when I’m trying to access to the dashboard settings, (it redirects me to http://admin.localhost:8000/users/1/edit but) the form is never appearing. The loader never stops. When I look at the DOM, the fields seem to be well generated.

image

I think it’s a DOM error. Here is the logs in the JS console.

image

Uncaught SyntaxError: Unexpected token &

Uncaught TypeError: Cannot read property 'medias' of undefined

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (5 by maintainers)

Most upvoted comments

Hi … again! I think I’ve found the issue … at least for me … In the blade template twill/layouts/form.blade.php there are some JS ojects that are initialized like below:

window.STORE.publication = {
        withPublicationToggle: {{ json_encode(($publish ?? true) && isset($item) && $item->isFillable('published')) }},
        published: {{ json_encode(isset($item) ? $item->published : false) }},

Please notice: {{ json_encode … is using {{ instead of {!! therefore the single quote is encoded to &quote; in the generated html page… and the error breaks loose afterwards…

Hope this is helpful for somebody.

Its because getLanguageLabelFromLocaleCode() in vendor\area17\twill\src\Helpers\i18n_helpers.php is using ucfirst in line 74 ucfirst(Locale::getDisplayLanguage($code, $code)).

Note that ‘alphabetic’ is determined by the current locale. For instance, in the default “C” locale characters such as umlaut-a (ä) will not be converted.

So when $code is ‘zh-Hans’ i.e. chinese simplified, it got translated by Locale::getDisplayLanguage($code, $code) to “中文” but ucfirst makes it b"ĸ­æ–‡" .

In simple words its i18n error. Function getLanguageLabelFromLocaleCode($code, $native = false) can’t get Language label from locale code.

@shabaz-ejaz Meanwhile you can change 2nd parameter to false on line 56: 'label’ => getLanguageLabelFromLocaleCode($locale, true) in vendor\area17\twill\views\users\form.blade.php.

@ifox Please Fix it.