我想要两个简单的输入框。
有一个loginName输入框,一个password输入框。
目前我将这两个输入框的值映射成一个“状态”。
现在,使用 NativeBase。我如何像他们在演示中那样动态显示“成功”“错误”? http://nativebase.io/docs/v0.5.9/components#successInputTextbox
我想要两个简单的输入框。
有一个loginName输入框,一个password输入框。
目前我将这两个输入框的值映射成一个“状态”。
现在,使用 NativeBase。我如何像他们在演示中那样动态显示“成功”“错误”? http://nativebase.io/docs/v0.5.9/components#successInputTextbox
传递一个道具success
就等于传递success={true}
所以如果你有像 inputSuccess 和 inputError 这样的状态变量,你可以这样做:
<InputGroup
iconRight
success={this.state.inputSuccess ? true : false}
error={this.state.inputError ? true : false}>
<Icon name='ios-checkmark-circle' style={{color:'#00C497'}}/>
<Input placeholder='Textbox'/>
</InputGroup>
Native Base 文档(2.12 版)有这个例子:
state = { error: 'Some error' };
// ...
<Content>
<Item error={this.state.error !== ''}>
<Input
placeholder='Textbox with Error Input'
error={'#d50000'}
/>
<Icon name='close-circle' />
</Item>
</Content>
里面的error prop<Input />
是设置错误颜色。无效状态在 item error 属性中设置。
基唐Himanshu回答。不需要设置false,这是成功和错误的默认值。此外,您还可以使用条件更改图标!
<InputGroup
iconRight
success={this.state.inputSuccess}
error={this.state.inputError}>
<Icon name={this.state.inputSuccess ? 'checkmark-circle' : 'close-circle'}/>
<Input placeholder='Textbox'/>
</InputGroup>