# sherlock-form

> 链尚网React-Native 组件库组件：Form

Latest version **1.0.1** (published 2017-07-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install sherlock-form
pnpm add sherlock-form
yarn add sherlock-form
bun add sherlock-form
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-07-25 |
| First published | 2017-07-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | beven |
| Keywords | sherlock, sherlock-mind, sherlock-form |

## Links

- npm: https://www.npmjs.com/package/sherlock-form
- npm.io page: https://npm.io/package/sherlock-form

## Dependencies (2)

- [dantejs](https://npm.io/package/dantejs.md) ^1.0.8
- [sherlock-base](https://npm.io/package/sherlock-base.md) 1.0.10

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-07-25
- 1.0.0 — 2017-07-25

## README

## sherlock-form

### 一、简介

链尚网React-Native 组件库组件：Form

用于组织表单数据，以及获取输入项表单的值


### 二、安装

    npm install sherlock-form --save

    或者使用我们的组件库: 

    npm install sherlock-mind --save

 ```js   
    import Form from 'sherlock-form'
    import {Form} from 'sherlock-mind';
```
    
     
### 三、用例
    
```js

    import Form from 'sherlock-form';
    //或者 
    import {Form} from 'sherlock-mind'

    
    import {TextInput} from 'react-native'

    //零配置使用 使用内置的表单
    <Form.TextInput></Form.TextInput>
    <Form.Checkbox></Form.Checkbox>
    //等等 

    //方案一:包裹一个第三方表单组件
    const ITextInput =  Form.Interface(TextInput);

    //方案二:设定change与value方式包裹
    // onChange 为Checkbox 组件输入改变时，用于Interface内部同步value使用 
    // checked 为设置checkbox组件值得属性名 
    const ICheckbox = Form.Interface(ICheckbox,'onChange','checked');

    //方案三：复杂组件包裹
    const IList = Form.Interface((props,formRef)=>{
      return (<List {...props} onSelected={formRef.onNativeFormChange}  value={formRef.value} ></List>);
    })

    //方案四：继承方式实现
    class ProductNameList extends Form.ValueInterface{
        constructor(props){
          super(props);
          this.state  ={nameList:[]};
          this.setSelected = this.setSelected.bind(this);
        }
       /**
        *  重要：
              用于判断是否为输入型组件,如果是输入型组件，则在表单组件onChange时 强制渲染
              具体参见 ValueInterface 
              set value(){ 
                ...
                if(this.isInputControl){
                  this.forceUpdate();
                }
              }
              否则在onChange时不触发刷新
              从而提高性能
        */
        isInputControl = false

        componentDidMount(){
          this.remoteList().then((items)=>{
            this.setState({nameList:items});
          })
        }

        setSelected(item){
          this.value = item;
        }

        remoteList(){
          //this.contxt.form 由 <Form></Form>提供
          var data = this.context.form.getValue();
          return fetch('https://p.lianshang.com/product/name-list',{userName:data.userName});
        }

        render(){
          return (<List data={this.state.nameList} getSelected={}  selectedItem={this.value}></List>);
        }
    }
    

    class Demo extends React.Component{

      constructor(props){
        super(props);
        this.submit = this.submit.bind(this);
        this.formRef = (instance)=>{
          this.form = instance;
        }
      }

      submit(){
        var data = this.form.data;
        /**
         *  data:  {
              userName:'xxxx',
              password:'xxx',
              agreement:true/false,
              favorite:['足球','...'],
              productName:'灯芯绒'
            }
         */
      }

      render(){
            //Form: onChange 当表单容器中任意表单发生改变时触发
            //Interface: onChangeValue: 当当前表单值发生改变时触发
            <Form ref={this.formRef}  onChange={(v,item)=>...}  >
              <ITextInput name="userName" value="sss" />
              <ITextInput name="password" secureTextEntry={true}  value="sss" />
              <ICheckbox name="agreement" checked={this.state.checked}>
              <IList name="favorite" onChangeValue={(v)=>console.log(v)  }>
                <List.Item>足球</List.Item>
                <List.Item>篮球</List.Item>
                <List.Item>皮球</List.Item>
              </IList>
              <ProductNameList name="productName" />
              <Button onPress={this.submit}>
          </Form>
      }
    }


```


### 四、开源许可
基于 [MIT License](http://zh.wikipedia.org/wiki/MIT_License) 开源，使用代码只需说明来源，或者引用 [license.txt](https://github.com/sofish/typo.css/blob/master/license.txt) 即可。

---
_Source: https://npm.io/package/sherlock-form · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
