Skip to content

Commit c854ea9

Browse files
committed
fix(pages): write Validation on date pickers and text areas
Only the text box carried its Forms$WidgetValidation; Validation: on a date picker or text area was accepted and dropped. Wire both through builder, writer and describe, and make MDL-WIDGET07 on Required: name the spelling Studio Pro's Required preset actually stores ($value != empty). Field run: ProcureFlow (Mendix 11.14.0) scratch copy — dpFrom with Validation '$value != empty': stored, described, mx check 0 errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D5dJ4raEjbm8bFiKeYtchS
1 parent 9509176 commit c854ea9

13 files changed

Lines changed: 97 additions & 4 deletions

‎.claude/skills/fix-issue/findings/mdl-executor.jsonl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,3 +713,4 @@
713713
{"area": "mdl/executor", "date": "2026-09-25", "symptom": "`textbox t (Attribute: FullName)` at the top of a page (CREATE PAGE/SNIPPET, a plain container, or ALTER PAGE … INSERT at page level) passed plain `mxcli check`, `exec --no-check`/ALTER reported success, and `bson dump` showed `AttributeRef: null` — mxbuild 11.13.0: CE0544 \"This widget can only function inside a data context\" + CE7005 (textbox/textarea/datepicker/checkbox/radiobuttons/dropdown), CE0402 (dynamictext Attribute:), CE0642 (combobox). Qualified `Mod.Ent.Attr` there is stored and fails CE0544/CE2421/CE1365/CE7247 \"Move this widget into a data container\" + CE7006. `Attribute: $P/Attr` / `$currentObject/Attr` dropped even INSIDE a data view.", "cause": "resolveAttributePath returns the bare name when entityContext is \"\", and attributeRefToGen (and widgetobj setAttributeRefField) write nil for any path with < 2 dots, so the binding vanished between builder and writer; refuseBareAttributeRefs never sees it because no Attribute string is emitted. The only refusal (validatePageContextTree) runs in the --references phase for CREATE PAGE/SNIPPET, so plain check, --no-check and ALTER were unguarded. `$x/Attr` parses via the generic property rule as an *ast.DataSourceV3, so GetAttribute() returns \"\" and every builder skipped it.", "file": "mdl/executor/cmd_pages_input_binding_context.go (inputBindingProblem, checkInputBinding, validateInputBindingContext = MDL-WIDGET34), wired in cmd_pages_builder_v3_widgets.go (6 input builders + buildDynamicTextV3), widget_engine.go (primary Attribute mapping), validate_widgets.go (validateWidgetTreeIn); tests cmd_pages_input_binding_context_test.go; bug-tests input-binding-without-context{,.fail}.mdl", "insight": "Reuse the MDL-PAGEARG01 three-state context (pageArgContext known/present) rather than entityContext==\"\" as the 'outside a data container' signal: entityContext is also empty INSIDE a container whose flow cannot be resolved (excluded ShareFeedback_Logo), where DESCRIBE writes qualified names that must keep building — refusing qualified-on-empty-entity would have broken that round trip. So known-absent context refuses bare AND qualified; unknown context (ALTER) refuses only the bare name the writer provably nulls. Two existing unit tests (OnChangeSurvivesBuilder, DynamicTextV3_AttributeBinds) built inputs with NO entity and passed — the second asserted a bare `Title` AttributeRef counted as 'bound', i.e. it pinned the bug: when a fixture has no entity context, ask what the writer does with its output. The `$P/Attr` drop was found only by dumping the control page, not from the report — print the AST value type with a probe test before assuming a spelling reaches the builder. Evidence: 22 mxbuild errors before on the probe matrix; after, every case refused with nothing written, controls (dataview/listview/gallery/datagrid/snippet dataview/ALTER into dataview) 0 errors, 17/17 stock pages + 4/4 snippets describe→exec round trip.", "refs": ["MDL-WIDGET34"], "ce": ["CE0544", "CE7005", "CE0402", "CE0642", "CE2421", "CE1365", "CE7247", "CE7006"]}
714714
{"area":"mdl/executor","date":"2026-09-25","symptom":"`alter page FeedbackModule.ShareFeedback_Logo { insert after textBox1 { image zzImg (ImageType: imageUrl, ImageUrl: '{1}', ImageUrlParams: [{1} = ImageB64]) } }` passed `check --references`; exec wrote a bare AttributeRef and `mx check` could not LOAD the project (ArgumentNullException setting 'Attribute'). Same at page top level outside any data container; a text box's `Attribute:` there is silently dropped (CE7005).","cause":"ALTER's entity context comes from the STORED document (nearest enclosing data source, or a flow source's return type via resolveDataSourceFlowEntity). With the flow missing (Feedback v4.0.2 ships no DS_FeedbackForm) or no container at all, entityContext is \"\" and resolveAttributePath returns the bare name. CREATE PAGE refused this at check time (relaxExcludedWidgetRefs/unscopedBindings, #678); ALTER's check never opened the document, so nothing could know the scope.","file":"mdl/executor/validate_alter_unscoped.go, mdl/executor/cmd_alter_page.go (alterEntityContext), mdl/executor/validate.go (bindingsWithoutScope)","insight":"For ALTER, scope is a property of the stored document, not the statement: a check-time question about it must open the document (OpenPageForMutation, never Save; validate_alter_set.go already does this) and ask through the SAME function exec uses, so the INSERT/REPLACE entity resolution was lifted into alterEntityContext rather than restated, and the binding walk lifted out of unscopedBindings (bindingsWithoutScope) rather than copied. Controls that keep it from blocking working scripts: skip a target the stored doc lacks (added earlier in the script), a flow the script declares with an entity return (sc.flowParams), DataGrid2 column and list-view-template paths, and documents the script creates. Reproduce with a Studio Pro-authored page whose flow is genuinely absent.","refs":["#678","#685"]}
715715
{"area": "mdl/executor", "date": "2026-09-25", "symptom": "`describe page` on a File Uploader (files mode) emits `DataSource: association …`, and exec of that output fails: \"widget `upFiles` (fileuploader) exposes 2 datasources, so a generic `datasource:` clause is ambiguous — name the one you mean: associatedFiles, associatedImages\"", "cause": "DESCRIBE chose generic vs named by counting CONFIGURED datasources (namedCustomWidgetDataSources drops unset ones, so files mode = 1), while the builder's refuseAmbiguousGenericDataSource counts DECLARED datasource mappings (a generated def maps every top-level datasource = 2). Two sides of one round trip deciding the same question from different evidence.", "file": "mdl/executor/cmd_pages_describe_parse.go", "insight": "When describe and build each decide 'is this ambiguous?', they must count the same set. Fix read the DECLARED count from the stored schema (PropertyTypes with ValueType.Type=DataSource, excluding IsLinked) and excluded widgets with an embedded .def.json — those are hand-written and pick one datasource mapping per mode, so a database-mode ComboBox (two declared) must keep the generic clause. The #956 bug-test script itself authored the refused generic clause on a File Uploader: a bug-test that only runs `mxcli check` without a project can't see an exec-time refusal, so grep bug-tests for the old spelling whenever a builder starts refusing one.", "refs": ["mendixlabs/mxcli#1199", "mendixlabs/mxcli#956", "mendixlabs/mxcli#1109"], "rules": []}
716+
{"area": "mdl/executor", "date": "2026-09-26", "symptom": "`datepicker d (Attribute: From, Validation: '$value != empty', ValidationMessage: 'Pick a date.')` (or a textarea): check clean, exec 'Created page', describe shows no Validation, stored WidgetValidation empty. Authors asking for Studio Pro's 'Required' wrote `Required: true` and got only a generic MDL-WIDGET07", "cause": "The #550 fix wired ValidationExpression/Message through TextBox only; TextArea/DatePicker writers kept widgetValidationToGen() (empty) and their builders never read the keys, while `Validation` sat in the type-agnostic staticWidgetKnownProps so no warning fired.", "file": "mdl/backend/modelsdk/widget_write.go", "insight": "Studio Pro's Validation 'Required' is a UI preset that stores the expression `$value != empty` (strings: `length(toString($value)) > 0`) — visible as literal strings in the modeler's WebUI assembly (Mendix.Modeler.WebUI.dll) next to the other presets (E-mail, Positive number, Date in the future). There is no required flag after 7.6 (TextBox.required/requiredMessage deleted in 7.6.0 per the gen version table). A fix scoped to one widget of a family that shares the element leaves the siblings silently broken: grep the writer for every call of the default constructor.", "rules": ["MDL-WIDGET07"]}

‎.claude/skills/mendix/create-page/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Both are optional and can be changed later with `alter page … { set Class = '
6868
| Attribute binding | `attribute: AttrName` | `textbox txt (label: 'Name', attribute: Name)` |
6969
| Attribute over an association | `attribute: Assoc/Attr` (bare association name, multi-hop OK) | `textbox txt (label: 'Rule', attribute: RuleAction_BusinessRule/Name)` |
7070
| Password field | `Password: true` | `textbox tbPw (attribute: Secret, Password: true)` |
71-
| Widget validation | `Validation: '<expr>'` + `ValidationMessage: '<text>'` | `Validation: 'length(toString($value)) > 0'` — quoted, not `[bracketed]` |
71+
| Widget validation | `Validation: '<expr>'` + `ValidationMessage: '<text>'` | `Validation: 'length(toString($value)) > 0'` — quoted, not `[bracketed]`; on `textbox`, `textarea`, `datepicker`. "Required" is `Validation: '$value != empty'` (no `Required:` key) |
7272
| Variable binding | `datasource: $Var` | `dataview dv (datasource: $Product) { ... }` |
7373
| Action binding | `action: type` | `actionbutton btn (caption: 'Save', action: save_changes)` |
7474
| Database source | `datasource: database entity` | `datagrid dg (datasource: database Module.Entity)` |

‎.claude/skills/mendix/create-page/reference/widgets.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,16 @@ textbox txtName (label: 'Label', attribute: attributename)
469469
textarea txtDescription (label: 'Description', attribute: description)
470470
```
471471

472+
**Validation** — `textbox`, `textarea` and `datepicker` take Studio Pro's
473+
Validation group: `Validation:` is a Mendix expression over `$value`, quoted, and
474+
`ValidationMessage:` the text shown when it is false. Studio Pro's "Required" is
475+
not a flag but a preset of the expression `$value != empty`, so there is no
476+
`Required:` key (it is MDL-WIDGET07):
477+
```sql
478+
datepicker dpDue (label: 'Due date', attribute: DueDate,
479+
Validation: '$value != empty', ValidationMessage: 'Pick a due date.')
480+
```
481+
472482
**CHECKBOX** - Boolean checkbox:
473483
```sql
474484
checkbox cbActive (label: 'Active', attribute: IsActive)

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1414

1515
### Fixed
1616

17+
- **`Validation:` on a date picker or a text area was dropped without a word** — only the text box carried its `Forms$WidgetValidation` (ako/mxcli#550); the other two always wrote the empty element, so `datepicker d (…, Validation: '$value != empty', ValidationMessage: 'Pick a date.')` passed `check` and `exec` and validated nothing. Both now store and `describe` it. Studio Pro's "Required" validation is a preset of exactly that expression, not a flag, and `Required:` on an input now draws an MDL-WIDGET07 that says so instead of suggesting a near-miss key.
1718
- **Keyword operators were fused in some stored expressions** — a page action's microflow argument `Flag: $a and $b` was stored as `$aand$b`, `if $x then 'a' else 'b'` as `if$xthen'a'else'b'`; the same in `contentparams` values, `send rest request … with (…)` parameters and a dynamic `execute database query`. Those four places took the expression's text without its whitespace; literals, `+` and `$currentObject` were unaffected, which is why it went unnoticed, and `check --references` passed. Measured by decoding the stored units on a Mendix 11.14.0 project. The expression is now stored as written, with MDL comments removed, as the microflow expression sites already did.
1819
- **An input bound to an attribute outside any data container was written with no binding** — `textbox t (Attribute: FullName)` at the top of a page (or of a snippet, or inside a plain container) has no entity to qualify the name with, and the writer stored it as `AttributeRef: null`. Plain `check` passed, `exec --no-check` and `alter page … insert` at page level said success, and mxbuild 11.13.0 failed the page with CE0544 "This widget can only function inside a data context" + CE7005 (text box, text area, date picker, check box, radio buttons, drop-down), CE0402 (dynamic text `Attribute:`) or CE0642 (combo box). A qualified attribute there is stored and fails the same way (CE0544 / CE2421 / CE1365 / CE7247 "Move this widget into a data container"). `Attribute: $P/Name` and `Attribute: $currentObject/Name` never parsed as an attribute path and were dropped even inside a data view. `check` now reports all three as **MDL-WIDGET34** (no project needed), and the page builder refuses them with the widget named, so nothing is written; `alter page` refuses a bare name it has no entity for. Place the widget in a data view, list view, gallery or data grid and bind the attribute by name.
1920
- **An expression property written in brackets was silently dropped** (mendixlabs/mxcli#750) — `dynamicclasses: [ if $currentObject/Featured then 'a' else 'b' ]`, the spelling #750 proposes, parsed as a list that no writer reads: `check` was clean, `exec` said `Created page`, and the widget was stored with no dynamic class. `alter page … set DynamicClasses = [ … ]` said `Altered page` and changed nothing, and a column's `DynamicCellClass` stored the list's text — tokens fused, `[if$x/Ythen'a'else'b']` — as its expression. Measured on a copy of a Mendix 11.14.0 project with the pre-fix binary. `mxcli check` now reports **MDL-WIDGET32** for `DynamicClasses` and `DynamicCellClass` written as a list (no project needed), and ALTER refuses it, so `check -p` reports that too. Write the expression quoted.

‎docs/01-project/MDL_QUICK_REFERENCE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ MDL uses explicit property declarations for pages:
14381438
| Attribute binding | `attribute: AttrName` | `textbox txt (label: 'Name', attribute: Name)` |
14391439
| Attribute over an association | `attribute: Assoc/Attr` (bare association name, multi-hop OK) | `textbox txt (label: 'Rule', attribute: RuleAction_BusinessRule/Name)` — works on textbox, textarea, datepicker, dropdown, checkbox and radiobuttons, the same as on a data grid column |
14401440
| Password field | `Password: true` on a textbox | `textbox tbPw (attribute: Secret, Password: true)` — omitted when false. Without it a describe → exec round trip turns a password field into a plaintext one |
1441-
| Widget validation | `Validation: '<expression>'`, `ValidationMessage: '<text>'` | `Validation: 'length(toString($value)) > 0'` — a Mendix expression over `$value`, QUOTED not bracketed (`[...]` is the XPath spelling and parses as an array) |
1441+
| Widget validation | `Validation: '<expression>'`, `ValidationMessage: '<text>'` | `Validation: 'length(toString($value)) > 0'` — a Mendix expression over `$value`, QUOTED not bracketed (`[...]` is the XPath spelling and parses as an array). Written on `textbox`, `textarea` and `datepicker`. Studio Pro's "Required" is not a flag but this expression: `Validation: '$value != empty'` — a `Required:` key is MDL-WIDGET07 |
14421442
| Variable binding | `datasource: $Var` | `dataview dv (datasource: $Product) { ... }` |
14431443
| Action binding | `action: type` | `actionbutton btn (caption: 'Save', action: save_changes)` — the forms are a closed set (`mxcli syntax page.action`); anything else is **MDL-WIDGET28** |
14441444
| No action | `action: nothing` | `actionbutton btn (caption: 'Decorative', action: nothing)` — an explicitly inert control. Write it deliberately: an action keyword **short its argument** (`action: open_link` with no URL) is now an error rather than a widget silently written with no action at all |

‎mdl/backend/modelsdk/widget_write.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ func widgetToGen(w pages.Widget) (element.Element, error) {
574574
g.SetReadOnlyStyle("Inherit")
575575
g.SetSubmitBehaviour("OnEndEditing")
576576
g.SetSubmitOnInputDelay(300)
577-
g.SetValidation(widgetValidationToGen())
577+
g.SetValidation(widgetValidationToGenWith(x.ValidationExpression, x.ValidationMessage))
578578
return g, nil
579579

580580
case *pages.DatePicker:
@@ -597,7 +597,7 @@ func widgetToGen(w pages.Widget) (element.Element, error) {
597597
g.SetOnEnterAction(noActionGen())
598598
g.SetPlaceholderTemplate(textAsClientTemplate(x.Placeholder))
599599
g.SetReadOnlyStyle("Inherit")
600-
g.SetValidation(widgetValidationToGen())
600+
g.SetValidation(widgetValidationToGenWith(x.ValidationExpression, x.ValidationMessage))
601601
return g, nil
602602

603603
case *pages.RadioButtons:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
// Studio Pro's input-widget Validation (None / Required / Custom — "Required"
4+
// is a preset that stores the expression `$value != empty`) lives in the same
5+
// Forms$WidgetValidation on a text area and a date picker as on a text box.
6+
// Only the text box writer carried it (ako/mxcli#550); the other two always
7+
// wrote the empty element, so `Validation:` there was dropped with no warning.
8+
package modelsdkbackend
9+
10+
import (
11+
"testing"
12+
13+
"github.com/mendixlabs/mxcli/mdl/backend/bsonnav"
14+
"github.com/mendixlabs/mxcli/model"
15+
"github.com/mendixlabs/mxcli/sdk/pages"
16+
)
17+
18+
func TestWriteDatePickerAndTextArea_Validation(t *testing.T) {
19+
for name, w := range map[string]pages.Widget{
20+
"datepicker": &pages.DatePicker{
21+
BaseWidget: pages.BaseWidget{BaseElement: model.BaseElement{ID: "dp"}, Name: "dpFrom"},
22+
ValidationExpression: "$value != empty", ValidationMessage: "Pick a date.",
23+
},
24+
"textarea": &pages.TextArea{
25+
BaseWidget: pages.BaseWidget{BaseElement: model.BaseElement{ID: "ta"}, Name: "taNote"},
26+
ValidationExpression: "$value != empty", ValidationMessage: "Enter a note.",
27+
},
28+
} {
29+
d := encodeWidget(t, w)
30+
v := bsonnav.DGetDoc(d, "Validation")
31+
if v == nil {
32+
t.Fatalf("%s: no Forms$WidgetValidation", name)
33+
}
34+
if got := bsonnav.DGetString(v, "Expression"); got != "$value != empty" {
35+
t.Errorf("%s: Validation.Expression = %q, want the authored expression", name, got)
36+
}
37+
}
38+
}

‎mdl/executor/cmd_pages_builder_v3_widgets.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ func (pb *pageBuilder) buildTextAreaV3(w *ast.WidgetV3) (*pages.TextArea, error)
527527
if label := w.GetLabel(); label != "" {
528528
ta.Label = label
529529
}
530+
// Forms$WidgetValidation — the same Validation group as a text box.
531+
ta.ValidationExpression = w.GetStringProp("Validation")
532+
ta.ValidationMessage = w.GetStringProp("ValidationMessage")
530533

531534
// Handle OnChange (the "On change" client action)
532535
if err := pb.applyOnChangeV3(w, &ta.OnChangeAction); err != nil {
@@ -563,6 +566,9 @@ func (pb *pageBuilder) buildDatePickerV3(w *ast.WidgetV3) (*pages.DatePicker, er
563566
if label := w.GetLabel(); label != "" {
564567
dp.Label = label
565568
}
569+
// Forms$WidgetValidation — the same Validation group as a text box.
570+
dp.ValidationExpression = w.GetStringProp("Validation")
571+
dp.ValidationMessage = w.GetStringProp("ValidationMessage")
566572

567573
// Handle OnChange (the "On change" client action)
568574
if err := pb.applyOnChangeV3(w, &dp.OnChangeAction); err != nil {

‎mdl/executor/cmd_pages_describe_output.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ func outputWidgetMDLV3(ctx *ExecContext, w rawWidget, indent int) {
598598
if w.OnChange != "" {
599599
props = append(props, actionProp("OnChange", w.OnChange))
600600
}
601+
props = appendInputValidationProps(props, w)
601602
props = appendAppearanceProps(props, w)
602603
formatWidgetProps(ctx.Output, prefix, header, props, "\n")
603604

@@ -613,6 +614,7 @@ func outputWidgetMDLV3(ctx *ExecContext, w rawWidget, indent int) {
613614
if w.OnChange != "" {
614615
props = append(props, actionProp("OnChange", w.OnChange))
615616
}
617+
props = appendInputValidationProps(props, w)
616618
props = appendAppearanceProps(props, w)
617619
formatWidgetProps(ctx.Output, prefix, header, props, "\n")
618620

‎mdl/executor/cmd_pages_describe_parse.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,15 @@ func parseRawWidget(ctx *ExecContext, w map[string]any, parentEntityContext ...s
370370
widget.Caption = extractLabelText(ctx, w)
371371
widget.Content = extractAttributeRef(ctx, w)
372372
widget.Editable = extractEditable(ctx, w)
373+
widget.ValidationExpression, widget.ValidationMessage = extractWidgetValidation(ctx, w)
373374
widget.OnChange = extractOnChangeAction(ctx, w)
374375
return []rawWidget{widget}
375376

376377
case "Forms$DatePicker", "Pages$DatePicker":
377378
widget.Caption = extractLabelText(ctx, w)
378379
widget.Content = extractAttributeRef(ctx, w)
379380
widget.Editable = extractEditable(ctx, w)
381+
widget.ValidationExpression, widget.ValidationMessage = extractWidgetValidation(ctx, w)
380382
widget.OnChange = extractOnChangeAction(ctx, w)
381383
return []rawWidget{widget}
382384

0 commit comments

Comments
 (0)