Blueprint field readonly - Writes to disc on save

I have a field and in the blueprint it looks kind of like this for a field:

textfield:
  type: text
  readonly: true

1. Add a value

I add the textfield (readonly) value to my content text file.

2. Go to the panel page

I go to the panel page to make sure the textfield (readonly) value is there. It is, great!

3. Update the readonly value from the outside

I run a route with page($id)->update() to update the textfield (readonly) with a new value. The data is saved successfully. I can see that by looking at the content text file.

4. Save the panel without refresh

I’m still on the panel page which shows the old value, because no refresh is made. Now I click save. I expected this value to be skipped because it’s readonly, but instead my old value was overwritten.

Is readonly supposed to be overwritten?

For me a readonly should be read, not changed on save. What do you think?

Is there a workaround for me here, if I want to show the value but not overwrite it?

See this still open issue

1 Like

Yes, that’s another way of solving it and it also solves a bigger problem than mine. :slight_smile:

My take on it would be to check if the field was readonly and in that case don’t write it. I actually think my approach should apply as well, because, why is a readonly field written to disc? It should never be?

My workaround

I will probably make my fields hidden instead. Hopefully they are not written to disc that way? Then I will use another field to display them again.

True, there is no reason to write it.

1 Like

I created an issue on GitHub.

1 Like

did setting to hidden prevent panel from overriding the value?
did you use that in nja and kirby-ratings?

I don’t know and I don’t have this case available for testing anymore.

https://getkirby.com/docs/cheatsheet/panel-fields/hidden

Anyway, I think that the hidden field type keeps data from being overwritten by nothing. As far as I know it even keeps the data that are not used even if it’s not a hidden field. But the safer way for the future is probably to use a hidden field to not overwrite this data with nothing.

How it works with overwriting values with the same key that is already existing, I’m not sure.

The easiest thing is always to just test it, it only takes a minute.:wink:

Hidden fields and fields that are not listed in the blueprint are not overwritten.

1 Like