Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Captured initial values in getData() and made picker showing props no…
…t state
  • Loading branch information
Daniel Hanover committed Jul 5, 2018
commit d62b06f6a38f83e3a84178ccdd5a4095ebbf01df
4 changes: 2 additions & 2 deletions src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export class Form extends React.Component{
key: child.ref || child.type+i,
fieldRef : child.ref,
ref: child.ref,
onFocus:this.handleFieldFocused.bind(this),
onChange:this.handleFieldChange.bind(this, child.ref)
onFocus: this.handleFieldFocused.bind(this),
onChange: this.handleFieldChange.bind(this, child.ref)
}
));
}, this);
Expand Down
7 changes: 3 additions & 4 deletions src/fields/InputField.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export class InputField extends React.Component{
this.props.style
]}
containerStyle={[formStyles.fieldContainer,
formStyles.horizontalContainer,
this.props.containerStyle,
]}
formStyles.horizontalContainer,
this.props.containerStyle,
]}
/>
)
}
Expand Down Expand Up @@ -99,7 +99,6 @@ let formStyles = StyleSheet.create({
paddingRight: 10,
justifyContent: 'center',
lineHeight: 45,

},
input:{
paddingLeft: 10,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/DatePickerComponent.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {Field} from './Field';
export class DatePickerComponent extends React.Component{
constructor(props){
super(props);
if (props.value) {
// Ensure initial value is retrieved in Form.getData()
if(this.props.onChange) this.props.onChange(props.value, this.valid);
}
this.state = {
date: props.date? new Date(props.date) :'',
isPickerVisible: false
Expand Down
9 changes: 8 additions & 1 deletion src/lib/DatePickerComponent.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {Field} from './Field';
export class DatePickerComponent extends React.Component{
constructor(props){
super(props);
if (props.value) {
// Ensure initial value is retrieved in Form.getData()
if(this.props.onChange) this.props.onChange(props.value, this.valid);
}
this.state = {
date: props.date? new Date(props.date) : '',
isPickerVisible: false
Expand Down Expand Up @@ -41,6 +45,9 @@ export class DatePickerComponent extends React.Component{

// this.refs.picker.measure(this.getPickerLayout.bind(this));

_isPickerVisible() {
return this.state.isPickerVisible
}

_togglePicker(event){
this.setState({isPickerVisible:!this.state.isPickerVisible});
Expand Down Expand Up @@ -107,7 +114,7 @@ export class DatePickerComponent extends React.Component{

</View>
</Field>
{(this.state.isPickerVisible)?
{(this.props.showing)?
pickerWrapper : null
}

Expand Down
9 changes: 5 additions & 4 deletions src/lib/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {HelpText} from './HelpText';
let { View, StyleSheet, Text, TouchableHighlight} = require('react-native');
let { View, StyleSheet, Text, TouchableHighlight, TouchableOpacity} = require('react-native');

export class Field extends React.Component{
render(){
Expand All @@ -14,14 +14,15 @@ export class Field extends React.Component{
: null);

if(this.props.onPress){
return <TouchableHighlight onPress={this.props.onPress}>
return <TouchableOpacity style={{
}} onPress={this.props.onPress}>
<View>
{this.props.children}
{fieldHelpText}
</View>
</TouchableHighlight>
</TouchableOpacity>
}
return <View>
return <View>
{this.props.children}
{fieldHelpText}
</View>;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/InputComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export class InputComponent extends React.Component{
constructor(props){
super(props);

if (props.value) {
// Ensure initial value is retrieved in Form.getData()
if(this.props.onChange) this.props.onChange(props.value, this.valid);
}

this.triggerValidation = this.triggerValidation.bind(this);
// this.validate = this.validate.bind(this)
this.validate(props.value);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/LinkComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {Field} from './Field';
export class LinkComponent extends React.Component{
constructor(props){
super(props);
if (props.value) {
// Ensure initial value is retrieved in Form.getData()
if(this.props.onChange) this.props.onChange(props.value, this.valid);
}
this.state = {
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/lib/PickerComponent.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var PickerItem = Picker.Item;
export class PickerComponent extends React.Component{
constructor(props){
super(props);
if (props.value) {
// Ensure initial value is retrieved in Form.getData()
if(this.props.onChange) this.props.onChange(props.value, this.valid);
}
this.state = {
value: props.value || props.label,
}
Expand Down
6 changes: 5 additions & 1 deletion src/lib/PickerComponent.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ var PickerItem = Picker.Item;
export class PickerComponent extends React.Component{
constructor(props){
super(props);
if (props.value) {
// Ensure initial value is retrieved in Form.getData()
if(this.props.onChange) this.props.onChange(props.value, this.valid);
}
this.state = {
value: props.value,
isPickerVisible: false
Expand Down Expand Up @@ -144,7 +148,7 @@ export class PickerComponent extends React.Component{

</View>
</Field>
{(this.state.isPickerVisible)?
{(this.props.showing)?
pickerWrapper : null
}

Expand Down
5 changes: 5 additions & 0 deletions src/lib/SwitchComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {Field} from './Field';
export class SwitchComponent extends React.Component{
constructor(props){
super(props);
if (props.value) {
// Ensure initial value is retrieved in Form.getData()
if(this.props.onChange) this.props.onChange(props.value, this.valid);
}
this.state = {
value: props.value,
}
Expand Down Expand Up @@ -40,6 +44,7 @@ export class SwitchComponent extends React.Component{

<Text style={this.props.labelStyle}>{this.props.label}</Text>
<Switch
onTintColor={this.props.onTintColor}
onValueChange={this.handleValueChange.bind(this)}
style={this.props.switchStyle}
value={this.state.value} />
Expand Down
4 changes: 4 additions & 0 deletions src/lib/TimePickerComponent.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import {Field} from './Field';
export class TimePickerComponent extends React.Component{
constructor(props){
super(props);
if (props.value) {
// Ensure initial value is retrieved in Form.getData()
if(this.props.onChange) this.props.onChange(props.value, this.valid);
}
this.state = {
date: props.date? new Date(props.date) :'',
isPickerVisible: false
Expand Down