Using CodeMirror editor causes code errors #353
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: joomla/Component-Builder#353
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Steps to reproduce the issue
In JCB component configuration / Global tab set Select an editor to Editor - CodeMirror
Expected result
Able to edit code within JCB using the codemirror editor and save entered code
Actual result
When trying to save anything within JCB when code mirror is used get
Error
Invalid field: PHP getForm MethodTarget (array) $data values & (bool) $loadData & (object) $form & (int) $id (item id if found).
Invalid field: PHP postSaveHook MethodTarget (object) $model for the data model object and (array) $validData for the validated data.
Get similar errors in other areas. ANYWHERE that code is entered if you try to save you get similar errors.
You can't save anything if CodeMirror is the editor.
System information (as much as possible)
Additional comments
Using TinyMCE (or none) for editors works fine.
Would be very helpful to be able to use CodeMirror (or some other editor designed for code entry)
Please read over this issue 305 as you will see this has been an issue from the start.
So it is a Joomla bug as far as I can see, if anyone knows more they are welcome to point it out to me. For now just use the none/editor as the default and you should be okay.
The reality is with none of the default fields do we do much more then setup the xml for the field in JCB. So Joomla does the work in its own classes of converting the xml to the HTML you see on the page. So since it has a save error, I would assume they are doing something wrong in the editor. Other HTML editors work, just the codeMirrior that is causing issues.
I am open for suggestions here, since I agree it would be nice to get this resolve.
Just to add to this problem info. I can't save the custom form fields. It always give error" Unaccaptable value". I don't know if it's related to this issue and don't want to create duplicates.
What i noticed is:
This is on Bitnami with Codemirror as editor.
Well that field is a required field, and that is the expected result. So if you add code to it, does it save?
I honestly just gave up on this, momentarily.... The codemirror editor is just messing with the validation. Other editors for HTML no problem... but with codemirror I have not yet seen it work. But who knows some update may have fixed it. I have not tested it for a while now, so any feedback will help.
As you can see in background there is code. "//" is in there. Any recommendations on alternative editors to use? because no syntax highlight is kind of a pain in the butt.
There was code added. And this happens to all fields on custom buttons tab and the PHP tab. And probably more. The weird thing is. When the field contains already a value it works fine.
What i did now is disable code mirror from JCB settings. add two slashed in the fields i want to use. Then enable codemirror again and everything works fine from then on. Haven't been able to replicate this issue in default joomla components.
btw it doesn't matter much but i just figured i mention it. Looking at the history of this issue i totally get you not wanting to investigate further 👍 Much more important things to do in a day 😄
The validation is a simple JavaScript, and I am think if we improve it, we will have solved the problem.
Lets take the Site View as our focus on this script.
This is how Joomla's own component does the validation.
As you will see they have this
$this->form->getField('articletext')->save()
which adds JavaScript from the editor on the page. So depending on the editor you get something like this:But that is anyway after the
document.formvalidator.isValid(document.getElementById("item-form"))
so yes we can do some work on this, and I would really like to do this right.It has worked (the current JCB JavaScript) for almost everything, but not for the codemirror, so if anyone knows how to code that JavaScript right, step up.
I am wondering if we should not also move the JavaScript to the edit view (like Joomla content component), and remove the js file completely. So Joomla content component has one editor on the page/view but with JCB you can have many... and this seems where the challenge comes in.
Try this
Okay I did, and the issue remains, but the code is better so I will anyway use it.
I see at this point that it could be the show-hide custom script. Since all field already open, meaning those who loading when the page loads they submit even if they have no values only server side complains not the JavaScript validation. So this seem to relate to the custom show-hide scripts of JCB, like some initialization is missing.
Just a side note, I tested it with other code editor called
Rokpad
and then all gets saved, but the validations get ignored only server side complains.My "revised" 2ct.
Using the current staging, i'm able to modify and save both php and css editor fields.
The catch is that the fields already have to have data.
Trying to start and edit a "new/empty" field using codemirror fails on save.
As a workarround i change global editor to "none", then "create" the field by adding some dummy data and then saving. Next i revert back to "codemirror" to have the joy of syntax highlighting and continuing modification.
Looking into it a bit further (me and js ... its complicated)
a dirty, more convenient workaround.. on the adminpage with the field you want to start editing run do the following at your own risk
Note: For debugging purposses, the field can be rearmed by closing the edit option and saving the page
I am wondering what can we do to just fix this issue. Are we the only project that has run into this issue? Then it must be that I am doing something wrong... and I am very willing to add what ever code is needed to fix this.
Looking into it a bit further (me and js ... its complicated)
a dirty, more convenient workaround.. on the adminpage with the field you want to start editing run do the following at your own risk
Note: For debugging purposses, the field can be rearmed by closing the edit option and saving the page
another better "workaround" might be to add some JS to the governing Y/N button to set the "novalidate" class on its textarea when the text area is "opened".
as for the workaround, you can also add a bookmark with the following location to you browser
I know its dirty, and i'll continue to look at the root cause, but for now it serves me
Experimenting a bit with inspecting the objects of the text-area ( in my case field 55 in the administrator edit view ** Add CSS (views) * **.
jform_css_views_FAILSAVE.txt
jform_css_views_OK.txt
For best experience, use a diff viewer on the files
Initial observation that
strangely enough the entered text is nowhere in dump, but it remains in the "browser textarea"
Far as I can tell this has been resolved, and was never a JCB issue, but a codeMirrorJoomla issue. So I will close this, if any feel it needs another look let me know.