FaridSafi / react-native-gifted-form

📝 « One React-Native form component to rule them all »
MIT License
1.44k stars 214 forks source link

Switch onchange property #44

Closed markrickert closed 8 years ago

markrickert commented 8 years ago

Allows a user to specify an onChange property for switches.

Example usage:

<GiftedForm.SwitchWidget
  name='shippingEnabled'
  title='Charge Shipping?'
  ref='shippingEnabled'
  onChange={(value) => {
    console.log('Shipping enabled switched changed to: ' + value)
    this.forceUpdate()
  }}
/>

My editor made some whitespace fixes automatically as well. You can view this PR with ?w=1 at the end to get rid of these in the file viewer: https://github.com/FaridSafi/react-native-gifted-form/pull/44/files?w=1

FaridSafi commented 8 years ago

thank you @markrickert

xbogdan commented 7 years ago

This creates some weird circular calls. Any idea why ? It only happens if I want to access the value param. I tries using onValueChange but the value parameter of the function handleTest is always undefined and when using onChange some circular calls are getting triggered that don't stop.

The basic Switch component from react works fine with the my code.

      handleTest = (value) => {
           console.log(value)
      }

      <GiftedForm.SwitchWidget
        key={1000}
        title="test"
        // onValueChange={(value) => this.handleTest(value)}
        onChange={(value) => this.handleTest(value)}
        value={this.state.identifier}
      />