Skip to content

Commit

Permalink
Prep 0.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
RenaudLN committed Feb 3, 2025
1 parent 2a37021 commit 2cedab5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.14.4] - 2025-02-04
### Added
- Working right multiplication and division with dataframes

Expand Down
24 changes: 23 additions & 1 deletion examples/programmatic_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Annotated, ClassVar, Literal, get_args

import dash_mantine_components as dmc
from dash import Dash, Input, Output, State, _dash_renderer, dcc
from dash import Dash, Input, Output, State, _dash_renderer, dcc, no_update
from pydantic import BaseModel, Field, ValidationError, create_model, field_validator
from pydantic_core import PydanticUndefined

Expand Down Expand Up @@ -324,6 +324,7 @@ def create_form(form_definition, current_data):
form_id="dynamic",
form_cols=custom_model.form_cols,
form_layout=form_layout,
submit_on_enter=True,
), None
except Exception:
import traceback
Expand All @@ -332,5 +333,26 @@ def create_form(form_definition, current_data):
return dmc.Skeleton(dummy_output_store, h="4rem"), None


@app.callback(
Output(ModelForm.ids.errors("form-definition", "dynamic"), "data"),
Input(ModelForm.ids.form("form-definition", "dynamic"), "data-submit"),
State(ModelForm.ids.main("form-definition", "dynamic"), "data"),
State(ModelForm.ids.main("form-definition", "base"), "data"),
prevent_initial_call=True,
)
def check_dynamic_form(trigger, form_data, form_definition):
if not trigger:
return no_update
dynamic_model = CustomModel(**(form_definition or {})).to_model()
try:
dynamic_model.model_validate(form_data)
except ValidationError as exc:
errors = {
SEP.join([str(x) for i, x in enumerate(error["loc"]) if i != 2]): "Invalid value" for error in exc.errors()
}
return errors
return None


if __name__ == "__main__":
app.run(debug=True)
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def __init__( # noqa: PLR0912, PLR0913, PLR0915
"data-getvalues": None,
"data-restored": None,
"data-update": None,
"data-submit": None,
}
if not path
else {}
Expand Down

0 comments on commit 2cedab5

Please sign in to comment.