lines

look

Rows of fields with add and remove, totals and a balance check.

Drawn

1
2

pick an account for line 2

3
totalDebit2,718.40Credit2,668.50

out of balance · credit short by 49.90

fix 1 line and balance the entry to post entry

The sample

crates/blocks/src/kind/core/lines.rs:33–91

fn lines() -> Lines {
    let money =
        |name: &str, label: &str| -> Field { TextField::new(name).label(label).keyboard(Keyboard::Number).into() };
    let account: Field = PickerField::new("account")
        .label("Account")
        .options(vec![
            "6100 Rent".into(),
            "6200 Utilities".into(),
            "2100 Payables".into(),
        ])
        .into();
    let row = |id: &str, values: &[(&str, &str)]| LineItem {
        id: id.into(),
        values: values.iter().map(|(k, v)| ((*k).to_string(), (*v).into())).collect(),
    };
    let rows = vec![
        row(
            "l1",
            &[("account", "6100 Rent"), ("memo", "office rent"), ("debit", "2400")],
        ),
        row(
            "l2",
            &[("account", ""), ("memo", "power and water"), ("debit", "318.40")],
        ),
        row(
            "l3",
            &[
                ("account", "2100 Payables"),
                ("memo", "landlord"),
                ("credit", "2668.50"),
            ],
        ),
    ];
    let columns = vec![
        account,
        field("memo", "Description"),
        money("debit", "Debit"),
        money("credit", "Credit"),
    ];
    let error = RowError {
        row: Some("l2".into()),
        name: Some("account".into()),
        message: "pick an account for line 2".into(),
    };
    Lines::new("lines", columns, rows)
        .id("journal")
        .label("journal lines")
        .action("check-journal")
        .sum(vec!["debit".to_string(), "credit".to_string()])
        .balance(["debit".to_string(), "credit".to_string()])
        .min(2_u32)
        .adds("add line")
        .errors(vec![error])
        .submit(Submit {
            label: "post entry".into(),
            action: "post-journal".into(),
            ..Submit::default()
        })
}
{
  "blocks": [
    {
      "action": "check-journal",
      "add": "add line",
      "balance": [
        "debit",
        "credit"
      ],
      "columns": [
        {
          "label": "Account",
          "name": "account",
          "options": [
            "6100 Rent",
            "6200 Utilities",
            "2100 Payables"
          ],
          "type": "picker"
        },
        {
          "label": "Description",
          "name": "memo",
          "type": "text"
        },
        {
          "keyboard": "number",
          "label": "Debit",
          "name": "debit",
          "type": "text"
        },
        {
          "keyboard": "number",
          "label": "Credit",
          "name": "credit",
          "type": "text"
        }
      ],
      "errors": [
        {
          "message": "pick an account for line 2",
          "name": "account",
          "row": "l2"
        }
      ],
      "fallback": {
        "title": "journal lines"
      },
      "id": "journal",
      "items": [
        {
          "id": "l1",
          "values": {
            "account": "6100 Rent",
            "debit": "2400",
            "memo": "office rent"
          }
        },
        {
          "id": "l2",
          "values": {
            "account": "",
            "debit": "318.40",
            "memo": "power and water"
          }
        },
        {
          "id": "l3",
          "values": {
            "account": "2100 Payables",
            "credit": "2668.50",
            "memo": "landlord"
          }
        }
      ],
      "label": "journal lines",
      "min": 2,
      "name": "lines",
      "submit": {
        "action": "post-journal",
        "label": "post entry"
      },
      "sum": [
        "debit",
        "credit"
      ],
      "type": "lines"
    }
  ],
  "fallback": {
    "title": "screen"
  },
  "id": "lines",
  "type": "screen"
}

Its fallback

What a renderer without lines draws: a row from the fallback the block carries.
journal lines

Style hooks

.b-linesthe block
[data-block=lines]every block of the kind
[data-id=journal]this one block
Every page here is a blocks Screen, written by site::page: no hand-written HTML. Source: https://github.com/jirathip-dev/blocks