NetTalk Central

Author Topic: Text field on form set to read-only appears to be a string with no line feeds  (Read 4435 times)

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
When I place a Text field on a form it works as expected, scrollable and return creates new lines. However, if I change the field to read only I appear to get a read only string field with no box, no scrolling and line feeds are removed, basically just a continuous line of text. What am I doing incorrectly?

I'm using NT 12.17.

Any help would be appreciated, I'm sure it is just my lack of NT knowledge that is causing me difficulty.

Best Regards
Gordon

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
I'm looking for a way to add the readonly attribute to a textarea, something like this, readonly here is the final attribute before the content:

<textarea id="lvReadOnlyBox" name="lvReadOnlyBox" rows="4" cols="60" data-edit="redactor" class=" nt-redactor  nt-entry nt-entry-text" data-formproc="textboxtestform" data-dashlane-rid="05295b2c96f3c3af" data-form-type="other" readonly>Line 1
Line 2
</textarea>

At present the readonly flag in the webserver options changes the field from a text field to a string.

Anyone know how to do this?

Gordon

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
so, just to be sure, when this field is _not_ read-only then you are using the Redactor editor to edit the contents?

So some edit it in Redactor, and some get the Read-only version?

Or - is the field coming from a "plain text" value, as captured by some desktop program or something like that?

cheers
Bruce

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
ok, so I've done a bit of digging and found a bug for one place;
If the "Editor" option for the field is set to None, and the contents of the field are "plain text" then it behaves as you describe.

I have fixed it for the 20.22 build

You can change it in your netweb.clw by changing line circa 6577 from

    if instring('readonly',p_status,1,1) and (p_display = Net:Web:HtmlOk or p_editor)

to

    if instring('readonly',p_status,1,1) and (p_display = Net:Web:HtmlOk or p_editor > net:HTMLNone)

Cheers
Bruce

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Thank you for your help Bruce.

In answer to your first question some users get to edit and others only get to view.

The field is plain text (it does usually contain CR LF characters) and the Editor is currently set to default (which is Redactor or even if specifically set to Redactor), with these settings the html doesn't generate a textarea with the readonly attribute when the readonly flag it set, below is the actual html for the field:

<div id="textboxtestform_lvreadonlybox_value_div" class="nt-form-last-in-cell  nt-form-div">Line 1
Line 2
</div>

Having made the changes to NetWeb.clw you suggest, I do get a readonly textarea if I set the editor to None, which in this case is fine. However if I set the Editor to Redactor I still only get the div as above rather than a redactor textarea with the readonly attribute. Is it possible in a future release to implement a change to the html generation to add the read only attribute to a Redactor or other editor textarea?

In the meantime I have a fix for a Redactor editor (maybe the others too), I don't use the Text tab's read only options, I add 'nt-entry-readonly' to the Entry Class on the CSS tab of the field, I'm guessing I could make this conditional by using a string variable instead of the explicit string. This generates a readonly scrollable text area.

Many thanks
Gordon

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Correction, I was incorrect adding 'nt-entry-readonly' to the Entry Class only makes it look read only (dark background rather than white) in fact it is editable. So the only thing that actually works is adding the readonly attribute to the textarea, it would be a nice feature to have.

Works fine if Editor set to none and read only ticked

Gordon
« Last Edit: August 05, 2021, 01:42:04 AM by GordonF »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Hi Gordon,

If you have the editor set as Redactor, then you are telling the system that the field contains HTML.
So then in read-only mode it simply shows the field (which is HTML right?)

So in HTML CR/LF chars are ignored - html uses <p></p> or <br/> for line breaks. Which is why you see the text "run on".
Hence the mismatch - you are saying the "field contains html" - but then it doesn't.

Fortunately if you have this mix, then you can convert the existing data to HTML. It's easy enough to do. Run through the table, and pass the offending field through the Stringtheory LineEndings method. For example;

str StringTheory

Open(table)
Set(table)
Loop
  Next(table)
  if Errorcode() then break.
  str.SetValue(tab:someHtmlField)
  str.LineEndings(st:web)
  if str.instring('<') then cycle. ! quick check to see if the field already contains html.
  tab.SomeHTMLField = str.GetValue()
  Put(table)
End

As in all things it's important to match the contents of the field, with what the code is being told is in the field.
This comes up a _lot_ with String encodings as well.

Cheers
Bruce

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Hi Bruce,

Thank you for the clarification and I understand you explanation relating to HTML, although I still think it could be useful to be able to present the HMTL in a readonly scrollable textarea that looks on screen like the editable version.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
sorry, Gordon, I'm not following that last bit.

a) does the field contain HTML or plain text?
b) are you saying you want to see the HTML editor all disabled - ie the buttons etc?

GordonF

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Hi Bruce,

To be honest I'm only working with plain test at present and everything works perfectly with the editor set to None.

With regard to the html editor, my thinking was that it may be a requirement in some systems for a user to be able to review the actual html but not be able to change it as opposed to simply seeing the rendered html. However I currently have no application for this, I think I just got diverted from my main objective which was view only scrollable plain text and that works perfectly.

Gordon

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
>> To be honest I'm only working with plain test at present and everything works perfectly with the editor set to None.

yes, that makes sense - if the field contains text, with text line endings, then it'll work well in a text control.
If you want to switch to an HTML editor then you will need to start by converting all your existing text data to HTML data.
(typically by using the StringTheory LineEndings method.)

the important thing here is that the _data_ matches the _control_ you are using.

>> With regard to the html editor, my thinking was that it may be a requirement in some systems for a user to be able to review the actual html but not be able to change it as opposed to simply seeing the rendered html.

The ACE editor is suitable for displaying (or editing) raw HTML code. Or you can configure the CKEditor to include a "source" button.

If you pass raw HTML to a TEXT control they will see the HTML source code as well. So it seems like that's actually already covered for you.

Cheers
Bruce