TextInput readOnly property

TextInput is very useful since it is part of the canvas and we can place other objects above it. Thanks Cajoek & Dr Abstract!!
I've noticed the following problems with it:
If we do not set its readOnly parameter when constructing it (false by default) and later on:
a) we set its readOnly property to false (as we would do in an init function), TextInput doesn't work anymore. It doesn't let you type anything.
b) we set its readOnly property to true, it doesn't let you type anything, which is fine, but the text cursor is blinking while there shouldn't be any text cursor

Ah... we are dingbats. In the getter/setter for readOnly, we used:

that.htmlTag.setAttribute("readonly", readOnly);

// we should have used the property

that.htmlTag.readOnly = readOnly;

We keep the cursor there so you can select and copy it. Use:

textInput.focus = false;
textInput.enabled = false;

Probably could make the enabled = false auto set the focus false... will note that for ZIM 018. Would you say if we then set enabled = true it should automatically set the focus to true? Or should we remember the focus when we set enabled to false and set it back to whatever the focus was...

The readOnly has been patched in ZIM 017. Thanks for letting us know and welcome to the ZIM Forum! Get yourself a profile pic if you so desire.

thank you!

textIput.htmlTag.readOnly = false TextInput works fine but if set to true it shows the cursor if TextInput is clicked

using textInput.enabled solved both problems

textInput.enabled=false makes it readOnly and textInput.enabled=true a regular TextInput

the focus property set to true works OK if TextInput.enabled=true
but if enabled is set to false not only the cursor shows up but also the TextInput is not readOnly anymore you can type in it

keeping the cursor so that one can select and copy the text isn't consistent with how TextArea works (and people are used to). if TextInput can let us select the text even though it is readOnly (as TextArea does) it would be fantastic (multi-line TextInput as well)

yes, i think setting enabled=false should auto set focus to false
but if enabled=true the focus should not be auto set to true. remembering the focus is good but setting the focus back to where it was should be left as a choice

I see... the TextArea lets you select when readOnly but does not show the cursor. I think we should do the same with TextInput - which is what you have been saying all along.

I like the enable:false to stop being able to select. This works on TextInput but does not, at the moment, work on TextArea. So we will try and adjust TextArea... maybe setting css pointer-events to none on it will work.

For our testing, the InputText keeps its readOnly setting when enabled is set to true. If we set focus true when enabled is false the cursor comes in but we still can't type or select. I think once we remove the cursor if readOnly:true then that will be solved.

Your recommendation to just leave the focus alone when setting enabled true sounds good - if they want the focus to be there they can set it.

Multiline TextInput would be great. If this is something you have expertise in and would like to take on... that also would be great.

We are in busy times for the next two days... but perhaps on Sunday we can have another go at the above adjustments (but not multi-line).

Okay - this has been adjusted and patched in ZIM 017.

TextInput hides cursor on readOnly - still allows selection. This is like TextArea.

They both now hide cursor and selection (and editing) on enabled false.

The slight difference is that TexArea loses its selection on enabled false and then true whereas TextInput keeps its selection on enabled false and then true. We could probably record the TextArea selection when enabled is set to false and remake it when it is set to true. Will add that to ZIM 018 requests.

1 Like

thanks, so also into the codesection of https://zimjs.com/016/emitter code should not be editable and readonly .

We don't mind it editable - maybe someone wants to make a quick change before copying. It is not a big deal.

1 Like