So, when we want to show a user a single value and let them edit it on the form, we use a Field element. This form element is connected to a form attribute that has a specific data type. Depending on that type, the Platform offers one or more ways of displaying this kind of data. In the next few episodes we’ll take a closer look at how the Platform shows attributes of different types using the Field element. Let’s start with the Formatted Document attribute.
Remember our agreements we store in this catalog? Some time ago we decided to store their PDF files separately - in this information register down here. The register’s only dimension refers to the agreement this record belongs to. The register’s only resource stores the PDF version of the agreement, while the agreement text still sits in the catalog itself. We don’t want anything potentially bulky in the catalog, so let’s move the Text to the same register as well. Now we need to fix the item form, so I’m going here, deleting the Text element and adding a new independent Text attribute right here.
When the form is created on the server side, I need to fill out this attribute value with the value taken from the register. This code uses the register’s Get method, passing the current agreement reference inside of the Structure as a parameter. This method returns another Structure with all the resources in it, so I’m taking the Text element from the structure like this. I also want to save the agreement text into the register after the editing is done, so this is what I do. I’m creating a new register record using its manager’s object factory named CreateRecordManager. Then I’m filling out the record’s dimension with the current agreement reference, copying the agreement text, and saving the register record. Now let’s drop the Text attribute to the form and see how it all works. Looks good, except this field is a tiny bit smaller than I need for agreements like this one.
OK, let’s see if we can fix it. I can play with this Text element properties and turn on these MultiLine and ExtendedEdit flags.It helps a lot, although I could use some formatting options. You know - different font faces and sizes, pictures inside of the text, and stuff like that. OK. Let’s try and fix it.
First of all, we cannot implement this using the string-type attribute, right? Strings are basically plain texts. They can contain very few symbols we can use to format the text: line feed and tab are pretty much all there is. What we need instead of the String is called FormattedDocument. This smart guy knows not only how to show the text but also how to make it look awesome. Besides that, we need a set of commands we can use to change the text properties, insert links and pictures, etc. So, I’m adding a new command bar to the element list and telling it that it should take its commands from the text element. Being FormattedDocument, the text element has a full set of various formatting commands that go directly to the command bar.
Now we need to figure out what to do with this Text attribute we store the agreement text in. It also cannot keep the String type for the same reason - strings do not support formatting. Is there a FormattedDocument type among all types available in this list? Nope. So what do we do? Easy. We use ValueStorage. The thing with the ValueStorage is that the Platform treats it as a cat in a sack. It doesn’t know and doesn’t care what’s in there. It just puts in and gets out whatever you ask it to. So, we usually use ValueStorage to store bulky binary stuff - pictures, videos, documents of various formats, etc. But it can be easily used for data of any type the Platform does or does not know. Looks like the perfect fit (and the only choice) for our FormattedDocument.
Now we need to learn how to put this FormattedDocument cat into this ValueStorage sack and how to get it back out again. So, let me show you. This piece of code over here now returns a ValueStorage. It cannot be assigned to this FormattedDocument attribute directly. So this is what I do. This Get guy is the only method of the ValueStorage object and it, basically, just retrieves whatever is in there.
The same deal is with this line down here. We cannot put the FormattedDocument directly to the ValueStorage. So, we need to use this universal New object factory to convert it. Just like this. OK. Let’s see. I’m opening the Agreement, pasting its text to the Formatted Document, and now I can do all kinds of formatting right here. Now I’m saving the document and reading it back. All right. Looks perfect.