{"name":"@alifd/field","version":"2.0.2","description":"Fields can be used to manage data when it comes to form data manipulation and validation. After being associated with a component, the form data can be automatically written back, read, and verified.","main":"lib/index.js","module":"es/index.js","stylePath":"style.js","scripts":{"start":"build-scripts dev","build":"npm run build:demo && npm run build:es && npm run build:lib","build:demo":"build-scripts build","build:es":"rm -rf es && tsc -p ./tsconfig.build.json --outDir es --module esnext","build:lib":"rm -rf lib && tsc -p ./tsconfig.build.json --outDir lib --module commonjs","prepublishOnly":"npm run build","test":"cypress run --component -b chrome","test:head":"cypress open --component -b chrome","precommit":"lint-staged"},"lint-staged":{"@(src|test)/**/*.@(ts|tsx)":["eslint"],"**/*.@(js|ts|tsx|json)":["prettier --write","git add"]},"husky":{"hooks":{"commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},"license":"MIT","keywords":["react","component"],"dependencies":{"@alifd/validate":"^2.0.2","tslib":"^2.6.2"},"devDependencies":{"@alib/build-scripts":"^0.1.3","@alifd/eslint-config-next":"^2.0.0","@alifd/next":"^1.15.12","@commitlint/cli":"^8.1.0","@types/chai":"^4.3.11","@types/react":"^16.14.56","@types/react-dom":"^16.9.24","@typescript-eslint/eslint-plugin":"^6.13.2","@typescript-eslint/parser":"^6.13.2","@vitejs/plugin-react":"^4.2.1","build-plugin-component":"^1.0.0","build-plugin-fusion":"^0.1.0","build-plugin-moment-locales":"^0.1.0","chai":"^4.4.1","cypress":"^13.6.4","enzyme":"^3.10.0","enzyme-adapter-react-16":"^1.14.0","es6-promise-polyfill":"^1.2.0","eslint":"^8.56.0","eslint-config-prettier":"^9.1.0","eslint-plugin-cypress":"^2.15.1","eslint-plugin-import":"^2.29.1","eslint-plugin-markdown":"^3.0.1","eslint-plugin-react":"^7.14.2","eslint-plugin-tsdoc":"^0.2.17","husky":"^3.0.0","lint-staged":"^9.2.0","mocha":"^6.1.4","moment":"^2.24.0","prettier":"^3.2.4","prop-types":"^15.8.1","react":"^16.3.0","react-dom":"^16.8.6","react-redux":"^7.1.0","redux":"^4.0.4","semantic-release":"^17.2.3","sinon":"^16.1.3","typescript":"^4.9.5","vite":"^4.5.2"},"componentConfig":{"name":"field","title":"Field","categories":["表单"]},"homepage":"https://unpkg.com/@alifd/field@2.0.2/build/index.html","bugs":{"url":"https://github.com/alibaba-fusion/field/issues"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org"},"repository":{"type":"git","url":"git+https://github.com/alibaba-fusion/field.git"},"release":{"plugins":[["@semantic-release/commit-analyzer",{"releaseRules":[{"type":"typescript","release":"patch"},{"type":"revert","release":"patch"}],"parserOpts":{"noteKeywords":["BREAKING CHANGE","BREAKING CHANGES"]}}],"@semantic-release/release-notes-generator","@semantic-release/npm","@semantic-release/github"]},"types":"./lib/index.d.ts","gitHead":"774e477af8c97a21287c1401f2e2984ec3f7fed2","_id":"@alifd/field@2.0.2","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-S0fMfGM+DK6TG4LZUxSvJ7HpVz3RckuyjoQuqp1QNIAE2TxeRU7Im1aQ2kbsFKR5Z30yQs5fDjeva0V521F27A==","shasum":"25f11409b8e6417fc058fcdb347dc2f7165e50a4","tarball":"http://registry-npm.ywwl.com/@alifd/field/download/@alifd/field-2.0.2.tgz","fileCount":35,"unpackedSize":2080836,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCRFbzf4iWBIZw3uOrXT/NrrKN6wwZJxKC6DdR+WcshhgIgfveiCpyOUSYVtrVpcdCS6n4rGxXAs+ppmErDcF3xjqA="}],"size":433873,"noattachment":false,"key":"/@alifd/field/-/@alifd/field-2.0.2.tgz"},"_npmUser":{"name":"eternalsky","email":"wsj7552715@hotmail.com"},"directories":{},"maintainers":[{"name":"jiaqiu_chen","email":"kbbqbb@gmail.com"},{"name":"soberz","email":"710411486@qq.com"},{"name":"whatever_lll","email":"whatever6g@gmail.com"},{"name":"john-watson","email":"wangjiarui1924@gmail.com"},{"name":"eternalsky","email":"wsj7552715@hotmail.com"},{"name":"mark-ck","email":"muscle.mark.cheng@gmail.com"},{"name":"lakerswgq","email":"lakerswgq@gmail.com"},{"name":"no-repeat","email":"chenpeng.mini@gmail.com"},{"name":"wwsun","email":"ww.sun@outlook.com"},{"name":"aboutblank","email":"njuzhaoguoyan@foxmail.com"},{"name":"bindoon","email":"bindoon@sina.com"},{"name":"tao1991123","email":"tao360907796@gmail.com"},{"name":"vicerwang","email":"1060455478@qq.com"},{"name":"myronliu347","email":"myronliu347@gmail.com"},{"name":"jdkahn","email":"justindavidkahn@gmail.com"},{"name":"fusion-bot","email":"fusion-bot@alibaba-inc.com"},{"name":"sobear","email":"sobear.me@gmail.com"},{"name":"lianmin","email":"lianmin.slm@qq.com"},{"name":"clarkxia","email":"xiawenwu41@gmail.com"},{"name":"quanyin","email":"898617222@163.com"},{"name":"jerryyxu","email":"1193486072@qq.com"},{"name":"yellow2dong","email":"779509411@qq.com"},{"name":"alvinhui","email":"alvin.hui@qq.com"},{"name":"andevery","email":"hit.wpeng@gmail.com"},{"name":"luhengchang228","email":"luhengchang228@126.com"},{"name":"yuysmile","email":"879249235@qq.com"},{"name":"fd.xy","email":"galo.gm.work@gmail.com"},{"name":"rax-publisher","email":"rax-public@alibaba-inc.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/field_2.0.2_1717731163117_0.1993709033179012"},"_hasShrinkwrap":false,"readme":"# Field\n\n<p align=\"center\">\n  <a href=\"https://www.npmjs.org/package/@alifd/field\"><img src=\"https://img.shields.io/npm/v/@alifd/field.svg\"></a>\n  <a href=\"https://www.npmjs.org/package/@alifd/field\"><img src=\"https://img.shields.io/npm/dm/@alifd/field.svg\"></a>\n  <a href=\"https://codecov.io/gh/alibaba-fusion/field\"><img src=\"https://codecov.io/gh/alibaba-fusion/field/branch/master/graph/badge.svg\"></a>\n  <a href=\"https://travis-ci.com/alibaba-fusion/field\"><img src=\"https://travis-ci.com/alibaba-fusion/field.svg?branch=master\"></a>\n  <a href=\"http://makeapullrequest.com\"><img src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg\"></a>\n  <a href=\"https://github.com/alibaba-fusion/field/blob/master/LICENSE\"><img src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg\"></a>\n  <a href=\"https://github.com/semantic-release/semantic-release\"><img src=\"https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\"></a>\n</p>\n\n- category: Components\n-   family: DataEntry\n- chinese: 表单辅助工具\n- cols: 1\n- type: 表单\n\n---\n## Development Guide\n\n### When to use\n\nFields can be used to manage data when it comes to form data manipulation and validation. After being associated with a component, the form data can be automatically written back, read, and verified.\n\n### Use caution\n\n- With Field `init` components, `value` `onChange` must be placed in init's third argument, otherwise it may be overridden by init.\n- `Form` has been deeply optimized with `Field` for `data acquisition` and `automatic verification prompt`. It is recommended to use `Field` in `Form`. Please check Form demo.\n- initValue The defaultValue of a similar component, which only takes effect when the component first renders (the ajax asynchronous invocation setting initValue may have missed the first render)\n- with `parseName=true` you could use `getValues` to get a struct value, but not work in `getValue` you still need pass complete key\n\n### basic use\n\n```\nClass Demo extends React.Component {\n    Field = new Field(this); // instance creation\n\n    onClick = ()=>{\n        Console.log(this.field.getValue('name'));\n    }\n    Render() {\n        Const init = this.field.init;\n\n        // Note: initValue will only be assigned when the component is first initialized. If you are using an asynchronous assignment, use setValue\n        Return <div>\n            <Input {...init('name',{initValue:'first value'})} />\n            <button onClick={this.onClick>Get Data</button>\n        </div>\n    }\n}\n```\n\n### update data\n#### Event Updates\n\n```\nClass Demo extends React.Component {\n    Field = new Field(this);\n\n    onClick = ()=>{\n        this.field.setValue('name', 'newvalue'); // Assignment will automatically trigger render\n    }\n    Render() {\n        Const init = this.field.init;\n\n        Return <div>\n            <Input {...init('name')} />\n            <button onClick={this.onClick}>Settings</button>\n        </div>\n    }\n}\n```\n\n#### props update\n\n```\nClass Demo extends React.Component {\n    Field = new Field(this);\n\n    // Set the data before the component is mounted (this can be replaced with initValue)\n    componentWillMount() {\n        this.field.setValue('name', 'init Name')\n    }\n    // Receive data from props\n    componentWillReceiveProps(nextProps) {\n        this.field.setValue('name', nextProps.name)\n    }\n    Render() {\n        Const init = this.field.init;\n\n        Return <div>\n            <Input {...init('name')} />\n        </div>\n    }\n}\n```\n\n#### ajax update\n```\nClass Demo extends React.Component {\n    Field = new Field(this);\n\n    onClick = ()=>{\n        Ajax({\n            Url:'/demo.json',\n            Success:(json)=>{\n                // Update of assignment in callback event\n                this.field.setValue('name',json.name);\n            }\n        });\n    }\n    Render() {\n        Const init = this.field.init;\n\n        Return <div>\n            <Input {...init('name')} />\n            <button onClick={this.onClick}>Settings</button>\n        </div>\n    }\n}\n```\n#### onChange update monitoring\nTwo usages:\n1. Unified management\n\n```\nClass Demo extends React.Component {\n    Field = new Field(this,{\n        onChange:(name, value) => {\n          Switch(name) {\n            Case 'name1':\n              this.field.setValue('name2','value set by name1');\n              Break;\n            Case 'name2':\n              this.field.setValue('name1','value set by name2');\n              Break;\n          }\n        }\n    });\n    Render() {\n        Const init = this.field.init;\n\n        Return <div>\n          <Input {...init('name1')} />\n          <Input {...init('name2')} />\n        </div>\n    }\n}\n```\n\n2. Individual management\n\n```\nClass Demo extends React.Component {\n    Render() {\n        Const init = this.field.init;\n\n        Return <div>\n          <Input {...init('name1',{\n              Props:{\n                onChange:(v)=>{\n                  this.field.setValue('name2','value set by name1');\n                }\n              }\n            })} />\n          <Input {...init('name2',{\n              Props:{\n                onChange:(v)=>{\n                  this.field.setValue('name1','value set by name2');\n                }\n              }\n            })} />\n        </div>\n    }\n}\n```\n\nFor details, please check Demo Demo `Associate Control`\n\n## API\n### initialization\n```\nLet myfield = new Field(this [,options]);\n```\n\n|Parameter | Description | Type | Optional |Default |\n|-----------|------------------------------------------|------------|-------|--------|\n| this | The incoming call to this class | React.Component | must be set |\n| options | Some event configuration, detailed parameters are as follows | Object | Not required | |\n\n`options` configuration item\n\n| Parameters | Description | Type |Default |\n|-----------|------------------------------------------|-----------|--------|\n| onChange | all component changes will arrive here [setValue won't trigger the function] | Function(name,value) | |\n|parseName | Whether to translate `name` in `init(name)` (getValues ​​will convert a string with `.` to an object) | Boolean | false|\n|forceUpdate | Only the components of PureComponent are recommended to open this forced refresh function, which will cause performance problems (500 components as an example: the render will cost 700ms when it is turned on, and 400ms if it is turned off) | Boolean |false|\n| autoUnmount | Automatically delete the Unmout element, if you want to keep the data can be set to false | Boolean |true|\n| autoValidate | Automatically validate while value changed | Boolean  |true|\n| values | initial value| Object ||\n| processErrorMessage | function to transform error objects on validation. Main usage is to add `key` prop to React component | Function(error) ||\n| afterValidateRerender | function to perform any operations after components have rerendered to show validation results. | Function({errorGroup, options, instance}) - see [afterValidateRerender](#afterValidateRerender) for more information ||\n\n\n#### API Interface\nThe api interface provided by the object after `new` (eg `myfield.getValues()`) (The api function starting with `set` should not be manipulated in render, which may trigger an infinite loop)\n\n|Parameter | Description | Type | Optional |Default |\n|-----------|------------------------------------------|------------|-------|--------|\n|init | Initialize each component, [Detailed Parameters below] (#init))| Function(name:String, option:Object)| ||\n| getValues ​​| Get the value of a group of input controls. If no parameters are passed, get the values ​​of all components | Function([names: String[]]) |\n| getValue | get the value of a single input control | Function(name: String) |\n| setValues ​​| Sets the value of a set of input controls (triggers render, follow the use of react time) | Function(obj: Object) |\n| setValue | Sets the value of a single input control (triggers render, follow the use of react time) | Function(name: String, value) |\n| validateCallback | Validate and retrieve the values ​​of a set of input fields and Error. | Function([names: String[]], [options: Object], callback: Function(errors, values)) | | |\n| validatePromise | Validate and retrieve the values ​​of a set of input fields and Error. Returns a promise| Function([names: String[]], [options: Object], (optional) callback: Function(errors, values)) | | |\n|getError | Get Error of a Single Input Control | Function(name: String) | | |\n|getErrors | Get Errors of a Group of Input Controls | Function([name: String]) | | |\n|setError | Set Error for a Single Input Control | Function(name: String, errors:String/Array[String]) | | |\n|setErrors | Set Errors of a Group of Input Controls | Function(obj: Object) | | |\n|reset | reset the value of a group of input controls, clear the checksum | Function([names: String[]])| ||\n| resetToDefault | Resets the value of a group of input controls to the default | Function([names: String[]])| ||\n|getState | Judge check status | Function(name: String)| 'error' 'success' 'loading' '' | '' |\n| getNames | Get the key of all components | Function()| ||\n|remove | Delete the data of a certain control or a group of controls. After deletion, the validate/value associated with it will be cleared. | Function(name: String/String[])|\n| spliceArray  | delete data of name like name.{index} | Function(keyMatch: String, index: Number)|  |  |\n| watch | watch field value changes         | Function(names: String[], value: unknown, oldValue: unknown, triggerType: 'init' | 'change' | 'setValue' | 'unmount' | 'reset')                                      |                                |        |\n\n#### init\n```\ninit(name, options, props)\n```\n\n|Parameter | Description | Type | Optional |Default |\n|-----------|------------------------------------------|------------|-------|--------|\n| name | Required unique input control symbol | String |\n| options.valueName | attribute name of the component value, such as Checkbox is `checked`, Input is `value` | String | | 'value' |\n| options.initValue | The initial value of the component (the component will be read only when rendering for the first time, and later modifying this value is invalid), similar to defaultValue | any | | |\n|options.trigger | Name of the event that triggered the data change | String | | 'onChange' |\n| options.rules | Checksum Rules | Array/Object | | | |\n| options.getValueFormatter | custom way to get value from `onChange` event, Detailed usage see demo `custom data get` | Function(value, ...args) parameter order and components are exactly the same The | | | |\n| options.getValueFormatter | custom way to set value. Detailed usage see demo `custom data get` | Function(values) | | | |\n|props | Component-defined events can be written here | Object | | | |\n| autoValidate | Automatically validate while value changed | Boolean  |true|\n\nreturn\n\n```\n{id,value,onChange}\n```\n\n#### rules\n\n```\n{\n    rules:[{ required: true }]\n}\n```\n\nmultiple rule\n\n```\n{\n    rules:[{required:true,trigger:'onBlur'},{pattern:/abcd/,message:'match abcd'},{validator:(rule, value, callback)=>{callback('got error')}}]\n}\n```\n\n|Parameter | Description | Type | Optional |\n|-----------|------------------------------------------|------------|-------|--------|\n| required | cannot be empty| Boolean | true | `undefined/null/\"/[]` will trigger this rule)\n|pattern | check regular expression | regular | | |\n|minLength | Minimum string length / Minimum number of arrays | Number | | String/Number/Array |\n|maxLength | Maximum length of string / Maximum number of arrays | Number | | String/Number/Array |\n|length | string exact length / exact number of arrays | |number | | String/Number/Array |\n|min | Min | Number | | String/Number |\n|max | maximum | Number | | String/Number |\n| format | sum of common patterns | String | url, email, tel, number | String |\n| validator | Custom validation, (don't forget to execute `callback()` when validation is successful, otherwise validation will not return) | Function(rule,value,callback) |\n| trigger | Name of the event that triggered the check | String/Array | onChange/onBlur/... | onChange |\n| message | error message | String | | |\n\n## Custom Component Access to Field Standards\n\n- Supports controlled mode (value+onChange) `Must`\n     - value control component data display\n     - onChange callback function when the component changes (the first parameter can be given to value)\n\n- One complete operation throws an onChange event\n     For example, there is a process that indicates the status of the progress, it is recommended to increase the API `onProcess`; if there is a Start indicates the startup state, it is recommended to increase the API `onStart`\n\n- Clear data when `value={undefined}`, field's reset function will send undefined data to all components\n\n```\ncomponentWillReceiveProps(nextProps) {\n    if ('value' in nextProps ) {\n        this.setState({\n           value: nextProps.value === undefined? []: nextProps.value   //  set value after clear\n        })\n    }\n}\n```\n\n## <a name=\"afterValidateRerender\"></a> afterValidateRerender\n\n`afterValidateRerender` receives an object with the following properties\n\n|Parameter | Description | Type |\n|-----------|------------------------------------------|------------|-------|--------|\n| errorsGroup | Map of field elements with errors, indexed by name. Access the error by `errorsGroup[field_name].errors` | Object | \n| options | field's `options` property | Object | \n| instance | fields's `instance` property, which holds references to React components for the field items | Object | \n\n\n## Known Issues\n\n- Why doesn't the callback function enter the `this.field.validate` manually? A: Is it safe to define the validator method to ensure that the `callback` can be executed on any branch?\n","publish_time":1717731163296,"_cnpm_publish_time":1717731163296,"dist-tags":{"beta":"2.0.4-beta.0","latest":"2.0.4","next":"2.0.0"}}