【DataModel】Extending the standard writeback form - Labels and Input Types

Sharperlight communicates with a database by using its own datamodel. That datamodel is created using Sharperlight studio. If you have a database like this;
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/de02d9c4-460b-bb39-f3a7-05313d1d4290.png)
The data model created in Sharperlight studio looks like this.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/43bf7888-aa26-bdd0-7173-cc1c62884d41.png)
The database schema is loaded.
The Sharperlight engine uses this information to dynamically construct queries and retrieve data from the target database.

Normally, it is a one-way **read only**, but there is an option to allow data to be written.
For example, look at the options in the `Transaction` table. The **Allow Table Writeback** option is **True**. Setting this option to **True** allows data to be written to this table.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/de8a78ec-60e9-6d53-0927-e60971ec19f8.png)

Tables with this option set to True will have the `Standard Online Writeback Form` available.
Start the Sharperlight service and access the following address to display the form like this.
```
http://localhost/DemoRest/EntryForm/?productcode=TRAIN2&tablecode=Transactions
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/f32d5c26-1d1c-a8cb-d85b-973d2d52d9e8.png)
This standard writeback form is generated based on the table/field definitions of the datamodel above.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/25e22399-504b-a47f-fb63-2a9b60235ae3.png)
Note here, for example, the **Manufacture_ID** and **Model_ID** fields.
These fields are actually **ID**. However, on the standard writeback form, they are **Manufactures/Code** and **Models/Code** respectively.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/50d2d0ad-22f3-c7c0-6fde-eedb437a98ee.png)
Even when selecting a value, if you open the search window, you can select it with code like this.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/f6f047a4-4fdf-0bfa-b50e-8358d8bcc1dc.png)
This is because the Sharperlight engine uses the JOIN definitions defined in the datamodel to parse the definition of the destination table and look up the `Code` and `Name` fields.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/819368ce-45e2-34d2-938e-3eef74e5cb28.png)
JOIN TO table: Manufactures
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/9b2fc73f-0ac3-ecbc-a24b-b76e54509924.png)
JOIN TO table: Models
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/0b8eef55-b442-3f89-3f94-30716c4bc478.png)
So far, we have outlined the standard writeback form that is generated using the data model definition, but now we would like to extend it with two options.
### Changing the label ###
First, let's change this label. Currently, the table name of the JOIN destination and the code field name are displayed.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/53893dc0-ff5b-b319-6c60-5875508f5775.png)
Try changing this default setting.
Try to use the Description of the current field itself and change it like this:
Manufacture ID -> Car Manufacture
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/d773279e-9692-1269-a077-880ea5e9d895.png)
Model ID -> Car Model
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/055e841b-f0ee-58f3-7669-aa14bc8b8a0e.png)
Then set the **Use This Description** option to **True** for each field.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/93a916cc-18c1-bb3e-2748-5024aaa701d3.png)
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/9deae951-f609-21f5-542e-1810713af94d.png)
Save the data model and restart the Sharperlight service for the changes to take effect.
The writeback form now displays their own description.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/444df876-6ce8-c7d4-b0a0-721809637139.png)
### Changing input style ###
Now let's change the input style. Currently, the search window is displayed in a separate window.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/e5d67925-e88d-cbf9-ac06-6fbbf9333e74.png)
Let's change this to a dropdown list.
To do so, specify `DropDownList` in the **Input Style** option.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/f8141275-affa-aa04-8165-e5ba354d6166.png)
In this way, the writeback form now displays a dropdown list.
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2530698/b6831e5a-78a2-cf3b-8a6e-ee1216b6b8cb.png)