nips/101.md

76 lines
3.1 KiB
Markdown
Raw Normal View History

2024-04-23 05:29:28 +00:00
# NIP-101 - Forms On Nostr
2024-05-08 20:04:46 +00:00
`draft` `optional` `author:abhay-raizada`
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
The nip provides a way for users to create form templates on nostr, and for other users to be able to fill them.
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
## Form Template - Public
Event `30168` describes a form with `field` tags that contain the description of each form field, with optional settings
```js
2024-04-23 05:29:28 +00:00
{
"kind": 30168,
2024-05-08 20:04:46 +00:00
"content" : ""
"tags": [
["d", "<form identifier>"],
["name", "Name of the form"],
["settings", JSON.stringify({description: "<description of the form."})],
["field", "<fieldId>","<input-type>","<label for the field>","<Options (for option type)>", "<stringified JSON settings>"],
["field", "<fieldId>", "option", "label for options field",
JSON.stringify([["<optionId1>", "option label", "<optionId2>", "option label"]]),
"<stringified JSON settings>"})
]
],
2024-04-23 05:29:28 +00:00
"pubkey": "<Author of the form>"
}
```
2024-05-08 20:04:46 +00:00
The different tags used to describe the form are described as:
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
|Tags|Description|
|----|--------------
|d|The unique identifier of a form, for a user|
|name| A text serving as the name of the form|
|settings| An optional global config for the form.
|field| Contains the following values<table><tr><th>index</th><th>name</th><th>description</th></tr><tbody><tr><td>1</td><td>FieldId</td><td>an id that uniqely identifies a field in the forn</td></tr><tr><td>2</td><td>input-type</td><td>A field that describes the type of value that can be expected as a response to this field, values can be: `text`, `option` or `label`</td></tr><tr><td>3</td><td>label</td><td>A label for the field</td></tr><tr><td>4</td><td>options</td> <td>Only used for input-type option, is a Json stringified array of strings containing [`<OptionId`>, <`label`>, `<optional config>`] </td> </tr><tr><td>5</td><td>fieldSettings</td><td>An optional JSON stringified object that contains settings specific to the field, for example `renderElement`, a setting which indicates what UI element to render to the client </td></tr>
</tbody></table>
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
## Sharing and Private forms.
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
`<TBD>` similar to the sharing of spreadsheets as described in the proposed [NIP](https://github.com/nostr-protocol/nips/pull/1189).
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
## Responses - Public
2024-04-23 05:29:28 +00:00
Response events are attached to a form(3068 kind event), and the event data is stored in a `kind: 30169` event
Response structure:
2024-05-08 20:04:46 +00:00
```js
2024-04-23 05:29:28 +00:00
{
"kind": 30169,
2024-05-08 20:04:46 +00:00
"content" : "",
"tags": [["a", "30168:<pubkey of the author>:<form identifier>"],
["response", "<FieldId>", "<response as string>", "<stringified metadata object>"]],
2024-04-23 05:29:28 +00:00
"pubkey": "Author of Response"
}
```
2024-05-08 20:04:46 +00:00
for option fields, the response is the id of the option selected. In case of multiple-choice fields these id's maybe delimited by a semi-colon, ";", For example:
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
```js
{
"kind": 30169,
"content" : "",
"tags": [["a", "30168:<pubkey of the author>:<form identifier>"],
["response", "<FieldId>", "ZCZC;XCZXCZ;Z34Z", "<stringified metadata object>"]],
"pubkey": "Response author"
}
```
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
## Responses - Private
2024-04-23 05:29:28 +00:00
2024-05-08 20:04:46 +00:00
response tags are added to the ".content" field and encrypted as per the spec in [nip-44](./44.md)
2024-04-23 05:29:28 +00:00