joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.69k stars 3.63k forks source link

com_fields category fields change event causing problem in Persian fa-IR #16628

Closed farzadtaheri closed 6 years ago

farzadtaheri commented 7 years ago

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: ["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"]

dgrammatiko commented 7 years ago

@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

farzadtaheri commented 7 years ago

@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?

infograf768 commented 7 years ago

Anyone making this PR?

farzadtaheri commented 7 years ago

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();
                }
            }
dgrammatiko commented 7 years ago

@farzadtaheri yup, that was what I was suggesting

ViscountVic commented 7 years ago

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();
                    }
                }
ghost commented 7 years ago

can one of you Guys wrote the PR?

ViscountVic commented 7 years ago

I did PR - please look is all OK

dgrammatiko commented 7 years ago

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:

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

ViscountVic commented 7 years ago

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

Please restore back previous solution.

dgrammatiko commented 7 years ago

@ViscountVic what exactly is not working?

farzadtaheri commented 7 years ago

@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.

ViscountVic commented 7 years ago

@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

dgrammatiko commented 7 years ago

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

infograf768 commented 7 years ago

@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.

brianteeman commented 6 years ago

Was this resolved?

farzadtaheri commented 6 years ago

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

joomla-cms-bot commented 6 years ago

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

ghost commented 6 years ago

closed as having Pull Request #17859


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