Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
mobx-form-model
Advanced tools
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
// Simple Controller
import FormController from 'mobx-form-model';
const ctrl = new FormController('', [
({ value }) =>
value == null || !value.length ? { required: 'value required' } : undefined
]);
ctrl.valid; // false
ctrl.errors.required; // value required
ctrl.update('hello');
ctrl.valid; // true
ctrl.errors; // undefined
ctrl.dirty; // true
// nested controllers
import FormController, {
FormControllerGroup,
FormControllerArray
} from 'mobx-form-model';
const form = new FormControllerGroup({
name: new FormController('Tom'),
firstStep: new FormControllerGroup({
gender: new FormController(1),
birthday: new FormController('1990-01-01')
}),
questioins: new FormControllerArray([
new FormController(),
new FormController()
])
});
true
表示当前没有错误validator
执行玩合并后的结果controller
是否有效。false
表示当前controller
不会影响parent controller
的valid
、dirty
值。以上这些属性都是 observable
dirty
设置为false
,比如表单提交之前先检查dirty
,用户没修改表单就无需重复提交,那在表单提交后调用 markAsPristine()
就可以避免重复提交已经提交的表单。update(newValue) | 更新 value 标记 dirty 为 true 校验数据 |
replace(newValue) | 更新 value 校验数据 |
reset(newValue) | 更新 value 标记 dirty 为 false 校验数据 |
FAQs
Minimal form controller model based on Mobx
The npm package mobx-form-model receives a total of 3 weekly downloads. As such, mobx-form-model popularity was classified as not popular.
We found that mobx-form-model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.