Document is Working in progress. Welcome to fork :)
Minimal form model that supports to validating and dirty-checking based on Mobx.
Most features are copied from Angular forms
npm install -S mobx-form-model
Examples
// Simple Controller; const ctrl = '' value == null || !valuelength ? required: 'value required' : undefined; ctrlvalid; // falsectrlerrorsrequired; // value required ctrl;ctrlvalid; // truectrlerrors; // undefinedctrldirty; // true
// nested controllers; const form = name: 'Tom' firstStep: gender: 1 birthday: '1990-01-01' questioins: ;
Controller vs Group vs Array
Shared
Properties
- value,当前的值
- valid,
true
表示当前没有错误 - dirty, 表示值是否变更过。
- errors, 所有
validator
执行玩合并后的结果
- enabled, 表示当前
controller
是否有效。false
表示当前controller
不会影响parent controller
的valid
、dirty
值。
以上这些属性都是 observable
Methods
- disable()
- enable()
- markAsPristine() 将
dirty
设置为false
,比如表单提交之前先检查dirty
,用户没修改表单就无需重复提交,那在表单提交后调用markAsPristine()
就可以避免重复提交已经提交的表单。
Change Controler's value
update(newValue) | 更新 value 标记 dirty 为 true 校验数据 |
replace(newValue) | 更新 value 校验数据 |
reset(newValue) | 更新 value 标记 dirty 为 false 校验数据 |