This is a really disturbing problem. Sometimes when I add a new field the data is not saved and the language is switched back to the default one.
Today it was my Boiler field. I removed stuff to see where the problem was and it’s in the element
function. If I remove it, it works again.
This is my short code, a field (not a plugin) that causes the problem:
<?php
class BoilerField extends BaseField {
static public $fieldname = 'boiler';
//When this is removed the problem disapears
public function element() {
$element = parent::element();
$element->data('field', self::$fieldname); // SEEMS TO BE THIS LINE
return $element;
}
}
Blueprint
fields:
test:
label: Boiler
type: boiler
If I rename the fieldname everywhere to some_other_name
the problem disapears. Logout and login again did not fix the problem.
So:
- The problem only appears if the name everywhere is
boiler
.
- The problem only appears when I have the
element
function.
My guess is that you would not get any errors at all? That’s my experience of sessions. Really hard to solve.
Update
After more digging it seems to be this row:
$element->data('field', self::$fieldname);
I still don’t get it. How can this row change my sessions?
The problem remains if I keep it but change it like this:
$element->data('field', 'boiler');
Update 2
I added an animated gif. I var_dump
the brick object in the element
method.
- First I show when I comment (remove) the dangerous line of code. I save in both languages.
- Then I show when I uncomment (activate) the dangerous line of code. When I save in
de
the panel swiches back to en
.
I found it!
It did not had anything to do with this field at all.
Javascript from another field that was not in the blueprint caused it. I forgot to change the fieldname.
(function($) {
$.fn.myfield= function() {
return this.each(function() {
var field = $(this);
var fieldname = 'myfield';
So a field which is not in use, but contains javascript can screw up the language so that the page is not saved or overwritten by another language. It feels quite fragile.
Would it be possible to have the language in the panel less sensitive @lukasbestle and not so depending of the fields? Maybe it would be safer to use get variables only?
1 Like
I’m not really a Panel dev.
@bastianallgeier?
@lukasbestle Ahh, I see. You fix broken stuff and minor things and @bastianallgeier create the new big things?
I tested even more because I still got issues in some cases and I found out that the problem accur when I use an incorrect ajax route.
Ajax visit a page and in this case it was leading to an error page. I guess that’s why it switches to the default language.
http://localhost/kirby/panel/pages/some_field/field/undefined/boiler/ajax/
Anyway, I hope there is a way in the future to make more stable when it comes to keeping the chosen language.
I do create new features, but in Kirby and the Toolkit.
2 Likes
@jenstornell Hi Jens,
what do you mean by “So a field which is not in use, but contains javascript can screw up the language so that the page is not saved or overwritten by another language. It feels quite fragile.”?
We experience this “wrong language overwrite” bug a lot and it frustrates editors. I wonder now, if I can change sth in the template or blueprint to avoid this issue.
Thanks! Martin
Hi Martin!
I’m not sure how to get around it. I have a few plugins that suffer from it, often with ajax calls but not always.
About a month ago I added an issue about it: https://github.com/getkirby/panel/issues/943
It’s set for milestone 2.5 so hopefully we will see a fix in that version, but milestones can change.