Joomla-cms: com_fields category fields change event causing problem in Persian fa-IR

Created on 12 Jun 2017  Â·  19Comments  Â·  Source: joomla/joomla-cms

Steps to reproduce the issue

1- make sure you have more than two category for articles(com_content)
2- make sure you have at least a field for articles with context: com_content.article in com_fields
3- change back-end language to Persian(fa-IR).
4- go to Content > Articles. in Persian language the path is: محتوا > مطالب
5- edit an article and change category field value to another one.
6- after change category field value you see an error: DateTime::__construct(): Failed to parse time string (۱۳۹۶-۰۳-۰۶ ۰۳:۳۶:۰۲) at position 0 (�): Unexpected character

Expected result

dont show any error and fully reload page after ajax call

Actual result

after change category field value you see an error: DateTime::__construct(): Failed to parse time string (۱۳۹۶-۰۳-۰۶ ۰۳:۳۶:۰۲) at position 0 (�): Unexpected character

System information (as much as possible)

Joomla 3.7.x
PHP 5.6, 7.0, 7.1

Additional comments

I resolve this problem by editing this file:
/media/system/js/fields/calendar-locales/fa-ir.js
and comment line 19 : //localLangNumbers: ["Û°","Û±","Û²","Û³","Û´","Ûµ","Û¶","Û·","Û¸","Û¹"]

No Code Attached Yet

All 19 comments

@farzadtaheri commenting out the localisation string for numbers is not the right approach. The correct solution here will be to add this code:

        var elements = document.querySelectorAll(".field-calendar");

        for (var i = 0; i < elements.length; i++) {
            var element  = elements[i],
                instance = element._joomlaCalendar;

            if (instance) {
                instance.setAltValue();
            }
        }

In the fields category change event

@dgt41 yes it`s better idea.
I added the lines in this file:

administrator/components/com_fields/helpers/fields.php after line 345.

after this change error not shown again. :)

is that what you mean?

Anyone making this PR?

when i use this lines i get JavaScript error because (element) variable used in other lines. so i change the lines to this for resolve problem:

            var elements = document.querySelectorAll(".field-calendar");

            for (var i = 0; i < elements.length; i++) {
                var calendarfield  = elements[i],
                    instance = calendarfield._joomlaCalendar;

                if (instance) {
                    instance.setAltValue();
                }
            }

@farzadtaheri yup, that was what I was suggesting

I can confirm, solution working.
I added code after 345 line, but with little change:

var elements = document.querySelectorAll('.field-calendar');
                for (var i = 0; i < elements.length; i++) {
                    var calendarfield  = elements[i],
                        instance = calendarfield._joomlaCalendar;
                    if (instance) {
                        instance.setAltValue();
                    }
                }

can one of you Guys wrote the PR?

I did PR - please look is all OK

I am just pasting here my comments on @ViscountVic PR (which needs to be against Joomla's repo):

I would like to suggest a more decoupled snippet here (right now we are forcing calendar code into Fields and we actually fixing partially the problem, can still be a bug for other javascript dependant fields)
So here is my suggestion:

  • remove the added code
  • replace
element.form.submit();

with

var button = document.createElement('input');
button.style.display = 'none';
button.type = 'submit';
element.form.appendChild(button).click();

Now a proper submit event is bubbled and the calendar (or any script that needs to do anything before submitting a form) will process the data correctly.

PS Sorry for not suggesting this in the first place but I wasn't sure that this was the actual problem. By the way I tested the code and is working fine

New solution isn't working. I see animated icon without any result.

Please restore back previous solution.

@ViscountVic what exactly is not working?

@dgt41 , hi, i think we can do this with more simple change,
i replace the line

element.form.submit();

with

Joomla.submitform('field.storeform', element.form);

and everything is work.

amazing!!
with this change no need to add this lines even!

var elements = document.querySelectorAll('.field-calendar');
                for (var i = 0; i < elements.length; i++) {
                    var calendarfield  = elements[i],
                        instance = calendarfield._joomlaCalendar;
                    if (instance) {
                        instance.setAltValue();
                    }
               }

so for resolve main issue we just need change one line only (348) and nothing else.

@dgt41 I changed category and page showing updating animate image with white transparent background, but it is not finished, all time this animation, without access for edit article

@farzadtaheri if Joomla.submitform() works then that's a better solution!

@farzadtaheri
Please make a PR vs staging so we can test and get this in for 3.7.3
Add the link to the PR here. Thanks.

Was this resolved?

@brianteeman not yet, the problem change but not resolved! please check new PR #17859.

Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/16628

closed as having Pull Request #17859


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16628.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Shazrina1994 picture Shazrina1994  Â·  4Comments

brianteeman picture brianteeman  Â·  4Comments

MartijnMaandag picture MartijnMaandag  Â·  6Comments

alex7r picture alex7r  Â·  4Comments

Hils picture Hils  Â·  5Comments