?
avatar Flowman
Flowman
27 Jan 2017

Steps to reproduce the issue

Create a modal window form and have a category selector in it.

Try to change the category.

Expected result

Category should change.

Actual result

JavaScript error occurs:
Uncaught ReferenceError: categoryHasChanged is not defined

System information (as much as possible)

Joomla 3.7.0
PHP 7.1

Additional comments

What is the purpose of https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_fields/helpers/fields.php#L299

So in a modal window we don't really want to reload the page when we change a category.

avatar Flowman Flowman - open - 27 Jan 2017
avatar joomla-cms-bot joomla-cms-bot - change - 27 Jan 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 27 Jan 2017
avatar Bakual Bakual - edited - 27 Jan 2017
avatar Bakual
Bakual - comment - 27 Jan 2017

What modal window?
Sounds like it is missing the needed JavaScript. The reloading is necessary because the available fields may change when you change the category.

avatar Flowman
Flowman - comment - 27 Jan 2017

Custom form in a modal window that uses data-remote with a raw view.

And because com_fields take over the form load it will always try to inject the javascript from https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_fields/helpers/fields.php#L330 into the header. That is not possible in a modal window that uses data-remote with a raw view.

So yes it will always miss the javascript.

avatar laoneo
laoneo - comment - 27 Jan 2017

As I pointed out in this comment, this javascript block is on the wrong place actually. But honestly I don't know where to put it. @dgt41 any clue?

avatar dgt41
dgt41 - comment - 27 Jan 2017

The easy patch is to check

if (window.parent != window.top) {
window.parent.categoryHasChanged(element)....
}

But this just reveals the limitations of the current approach of building forms. Forms should, preferably be ajaxified, so no actual page reload is needed

avatar Flowman
Flowman - comment - 27 Jan 2017

@dgt41 that will not work as it a raw view modal. I does not have a header section where the field helper can put its JS.

avatar Bakual
Bakual - comment - 27 Jan 2017

Is that a modal which is supposed to support custom fields then?

avatar Flowman
Flowman - comment - 28 Jan 2017

I dose not matter as the code will inject to whatever form you create that has a category field with id catid. I can create a form on a page with just a category selector. As soon as I change the category it will reload the page. That is not the behavior I want when I just have a category selector in a component on the frontpage. Does that make sense? That is not have 3.6.x and previous version have been doing and will create BC for component that have a category selector.

I could change the ID to something else but then we need a converter in the code to match it up with the table on save.

avatar Flowman
Flowman - comment - 28 Jan 2017

I found a easy solution to the problem. Just remove the onchange from the field when the form is loaded in the view. This will override what the prepareForm function does.

avatar Bakual
Bakual - comment - 28 Jan 2017

I think, the whole code should actually first check if the extension is supposed to support com_fields (maybe check if the validateContext method exists?). At least I didn't see such a check.
If not, it may indeed have a chance to break things. At least it doesn't make sense to reload the form for each extension which has a category field.

avatar laoneo
laoneo - comment - 28 Jan 2017

It adds that code only when there are fields. If there are none, then the code is not added.

avatar joomla-cms-bot joomla-cms-bot - change - 28 Jan 2017
Title
[com_fileds] modal windows with category selector
[com_fields] modal windows with category selector
avatar joomla-cms-bot joomla-cms-bot - edited - 28 Jan 2017
avatar Bakual
Bakual - comment - 28 Jan 2017

It adds that code only when there are fields. If there are none, then the code is not added.

Ah true, somehow the blind cow in me missed that code.

Just remove the onchange from the field when the form is loaded in the view

So this would not work as soon as custom fields come into play. The 3rd party dev needs to provide some own code which deals with that situation then.

The best solution would be to check in the getFields if there is any fields with assigned categories. If not do not add the onchange value to the field.

According to @laoneo that wouldn't work either. You need to reload the page somehow to make sure the custom fields are appropriate for the selected category.
If your form doesn't support adding JavaScript then changes are high anyway that something is broken. Or how does for example the date picker work? Or the "on the fly" creation of categories?

@Flowman Is there any occurance of this issue in core? Or does this need a 3rd party extension? If so, can you provide a way to test it?
Otherwise I tend to say it's not a bug but it's the normal part of implementing a new feature into an extension. You need to adjust the code to cope with it.

avatar franz-wohlkoenig franz-wohlkoenig - change - 30 Mar 2017
Category com_fields
avatar joomla-cms-bot joomla-cms-bot - change - 30 Mar 2017
Title
[com_fields] modal windows with category selector
[com_fileds] modal windows with category selector
avatar joomla-cms-bot joomla-cms-bot - edited - 30 Mar 2017
avatar franz-wohlkoenig franz-wohlkoenig - change - 5 Apr 2017
Status New Closed - No Reply
Closed_Date 0000-00-00 00:00:00 2017-04-05 13:02:23
Closed_By franz-wohlkoenig
avatar joomla-cms-bot joomla-cms-bot - change - 5 Apr 2017
Title
[com_fileds] modal windows with category selector
[com_fields] modal windows with category selector
avatar joomla-cms-bot joomla-cms-bot - close - 5 Apr 2017
avatar joomla-cms-bot
joomla-cms-bot - comment - 5 Apr 2017
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 5 Apr 2017

closed as "No Reply"


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

Add a Comment

Login with GitHub to post a comment