Value-expression variables inside *…* / **…** segments no longer need backticks (the segment markers already mark code). Drop trailing spaces and de-tick value-expression variable names in tests and skill docs; keep backticks for string interpolation, call args, and method receivers. Co-authored-by: Cursor <cursoragent@cursor.com>
1.4 KiB
1.4 KiB
title: web form smoke description: Offline form fields / validate / submit (no listen). import web:ext/web/web.mq.md import articles:web-fixtures/db/articles.mq.md import json:lib/json.mq.md
main
store = > web.db url="sqlite:web-fixtures/data/form-smoke.db" schema = > articles.schema
store.init name=articles fields=schema
fields =
| 字段 | 标签 | 类型 | 必填 | 默认 |
|---|---|---|---|---|
| title | Title | text | true | |
| body | Body | textarea | false |
rules =
| 字段 | 规则 | 消息 |
|---|---|---|
| title | required | Title is required |
| title | max:120 | Title is too long |
f = > web.form table=articles action=insert
f = > f.fields fields=fields
f = > f.rules rules=rules
bad =
| title | body |
|---|---|
| hello |
v = > f.validate data=bad
ok = > json.get value=v key=ok
ok
print text=validate-should-fail
print text=validate-ok
good =
| title | body |
|---|---|
| From form | Body via submit |
sub = > f.submit data=good db=store
sok = > json.get value=sub key=ok
sok
print text=submit-ok
print text=submit-fail
rows = > store.select table=articles limit=10
n = > len value=rows
n>= 1
print text=db-ok
print text=db-fail
html = > f.render id=article
html
print text=render-ok
print text=render-fail