Edit box for html

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Templar
Cave Troll
Posts: 65
Joined: Wed Sep 20, 2017 9:24 pm

Edit box for html

Post by Templar »

Hi All,

I am trying to create an edit box so that the player can edit a spell description.
The description is in html code e.g. : <p>This field is for the long description</p>

The relevant code looks like this:

Code: Select all

[h: SaveToTableLink = macroLinkText("SaveToTable@this","all")]
[h: DescriptionTextArea="<textarea name='SpellDescription' cols= '100' rows='100'>" + encode(SpellDescription) + "</textarea>"]  
<html>
<body>
  [dialog("Spell"): {
    <form action="[r:SaveToTableLink]" method="json">
    <table border="1">
      <tr>
        <td align=left>{DescriptionTextArea}</td>
      </tr>
    </table>
    </form>}]
</body>
</html>
If I encode SpellDescription, the encoded html ends up in the edit box. But this is hard to edit.
If I don't encode SpellDescription, it ends up underneath the edit box.

Any idea how to get around this?
Templar

Templar
Cave Troll
Posts: 65
Joined: Wed Sep 20, 2017 9:24 pm

Re: Edit box for html

Post by Templar »

Actually I have another question. Its part of the same code.
I have a table data structure that looks like this:
["spellName":"A Pot of Smoke to Confuse and Choke","Discipline":"Alchemy","spellLevel":1,"castTime":1]

But the output from the form looks like this:
{"spellName":"A Pot of Smoke to Confuse and Choke","Discipline":"Alchemy","spellLevel":1,"castTime":1}

I am wracking my brains on how to convert the second to the first. Array to Object. I am sure this should be simple but I can't seem to get it.
I have been looking at all the json functions with no luck.

I know that I can do this:

Code: Select all

[h: myJsonObject = json.append("[]", "spellName:" + json.get(myJsonArray, "spellName"), "Discipline:" + json.get(myJsonArray, "Discipline"), "spellLevel:" + json.get(myJsonArray, "spellLevel"), "castTime:" + json.get(myJsonArray, "castTime"))]
But it just seems a bit clunky. it's just a matter of replacing a couple of "{" brackets with "[" brackets.
Is there no function for this?

Can anyone help please?
Templar

Templar
Cave Troll
Posts: 65
Joined: Wed Sep 20, 2017 9:24 pm

Re: Edit box for html

Post by Templar »

Actually I just looked closer at the output and realised that doesn't work either.
%!@^%#@!!
Templar

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Edit box for html

Post by aliasmask »

["spellName":"A Pot of Smoke to Confuse and Choke","Discipline":"Alchemy","spellLevel":1,"castTime":1]

Is not a valid json, so it would just be a string. If you want to make it a valid json you may be able to just replace the first and last characters. I assume that data is in a variable.

Code: Select all

[H: myVar = '["spellName":"A Pot of Smoke to Confuse and Choke","Discipline":"Alchemy","test":[],"spellLevel":1,"castTime":1]']
[H: json = replace(replace(myVar,"^\\[","{"),"\\]\$","}")]
[R: json.get(json,"Discipline")]
Tested, and this works. Now if you have nested []'s then it won't. You'll have to be more specific in your replace. ie "^\\[" and "\\]\$"

Code: Select all

[H: myVar = '["spellName":"A Pot of Smoke to Confuse and Choke","Discipline":"Alchemy","test":[],"spellLevel":1,"castTime":1]']
[H: json = replace(replace(myVar,"^\\[","{"),"\\]\$","}")]
[R: json.get(json,"Discipline")]

Templar
Cave Troll
Posts: 65
Joined: Wed Sep 20, 2017 9:24 pm

Re: Edit box for html

Post by Templar »

This is great and worked perfectly. Thank you very much.
I knew it was something like this but admit that I didn't understand the require characters to use in the replace command.
I was doing something more like this: replace(replace(myVar,"[","{"),"]","}").
Shows I need to do more learning.

Don't suppose you have an answer for the "Edit box for html" question above?
Templar

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Edit box for html

Post by aliasmask »

I recommend whenever building json's to use the functions rather than doing it manually. json.append() for arrays and json.set() for objects (named lists)

Post Reply

Return to “Macros”