{"id":28717238,"url":"https://github.com/edvardchen/mobx-form-model","last_synced_at":"2025-08-22T22:49:00.594Z","repository":{"id":57299642,"uuid":"148986728","full_name":"edvardchen/mobx-form-model","owner":"edvardchen","description":"Minimal form controller model based on Mobx","archived":false,"fork":false,"pushed_at":"2019-05-07T15:09:40.000Z","size":156,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-28T00:40:23.834Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edvardchen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-16T10:54:44.000Z","updated_at":"2019-05-07T15:09:42.000Z","dependencies_parsed_at":"2022-08-26T20:24:43.287Z","dependency_job_id":null,"html_url":"https://github.com/edvardchen/mobx-form-model","commit_stats":null,"previous_names":["nochapter/mobx-form-model"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/edvardchen/mobx-form-model","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edvardchen%2Fmobx-form-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edvardchen%2Fmobx-form-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edvardchen%2Fmobx-form-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edvardchen%2Fmobx-form-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edvardchen","download_url":"https://codeload.github.com/edvardchen/mobx-form-model/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edvardchen%2Fmobx-form-model/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263687157,"owners_count":23496089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-15T03:13:51.100Z","updated_at":"2025-07-05T05:07:33.936Z","avatar_url":"https://github.com/edvardchen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Document is Working in progress. Welcome to fork :)\n\nMinimal form model that supports to validating and dirty-checking based on [Mobx](https://mobx.js.org/).\n\nMost features are copied from [Angular forms](https://angular.io/guide/reactive-forms)\n\n```bash\nnpm install -S mobx-form-model\n```\n\n## Examples\n\n```javascript\n// Simple Controller\nimport FormController from 'mobx-form-model';\n\nconst ctrl = new FormController('', [\n  ({ value }) =\u003e\n    value == null || !value.length ? { required: 'value required' } : undefined\n]);\n\nctrl.valid; // false\nctrl.errors.required; // value required\n\nctrl.update('hello');\nctrl.valid; // true\nctrl.errors; // undefined\nctrl.dirty; // true\n```\n\n```javascript\n// nested controllers\nimport FormController, {\n  FormControllerGroup,\n  FormControllerArray\n} from 'mobx-form-model';\n\nconst form = new FormControllerGroup({\n  name: new FormController('Tom'),\n  firstStep: new FormControllerGroup({\n    gender: new FormController(1),\n    birthday: new FormController('1990-01-01')\n  }),\n  questioins: new FormControllerArray([\n    new FormController(),\n    new FormController()\n  ])\n});\n```\n\n## Controller vs Group vs Array\n\n### Shared\n\n#### Properties\n\n- value，当前的值\n- valid, `true` 表示当前没有错误\n- dirty, 表示值是否变更过。\n- errors, 所有`validator`执行玩合并后的结果\n\n* enabled, 表示当前`controller`是否有效。`false`表示当前`controller`不会影响`parent controller`的`valid`、`dirty`值。\n\n以上这些属性都是 [observable](https://mobx.js.org/refguide/observable.html)\n\n#### Methods\n\n- disable()\n- enable()\n- markAsPristine() 将`dirty`设置为`false`，比如表单提交之前先检查`dirty`，用户没修改表单就无需重复提交，那在表单提交后调用 `markAsPristine()` 就可以避免重复提交已经提交的表单。\n\n## Change Controler's value\n\n|                   |                                                              |\n| ----------------- | ------------------------------------------------------------ |\n| update(newValue)  | 更新 value\u003cbr/\u003e 标记 dirty 为 `true` \u003cbr/\u003e 校验数据          |\n| replace(newValue) | 更新 value\u003cbr/\u003e \u003cdel\u003e标记 dirty 为 true\u003c/del\u003e \u003cbr/\u003e 校验数据 |\n| reset(newValue)   | 更新 value\u003cbr/\u003e 标记 dirty 为 `false` \u003cbr/\u003e 校验数据         |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedvardchen%2Fmobx-form-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedvardchen%2Fmobx-form-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedvardchen%2Fmobx-form-model/lists"}