Tcomb-form-native: TextInput onBlur callback as option?

Created on 21 Mar 2016  路  5Comments  路  Source: gcanti/tcomb-form-native

  • tcomb-form-native v0.4.0
  • react-native v0.21.0

For the TextInput field type you list among other standard options onBlur, onEndEditing, onFocus and onSubmitEditing. Can you give an example of how a callback would be indicated for these options?

var options = {
  fields: {
    textField: {
      onFocus: [ How do I code the callback here? ]
    }
  }
};

I find this library to be immensely helpful. Thanks for all of your work!

Most helpful comment

Basically, you can do this @flyingace

let options = {
  fields: {
    textField: {
      onFocus: () => { console.log('Your code here'); },
      // or
      onFocus: this._myOnFocusFunction.bind(this),
    },
  },
}

_myOnFocusFunction () {
  // Your code here
}

All 5 comments

Hi @flyingace,

onFocus will be passed to the native TextInput component as it is

https://github.com/gcanti/tcomb-form-native/blob/master/lib/templates/bootstrap/textbox.js#L44

Basically, you can do this @flyingace

let options = {
  fields: {
    textField: {
      onFocus: () => { console.log('Your code here'); },
      // or
      onFocus: this._myOnFocusFunction.bind(this),
    },
  },
}

_myOnFocusFunction () {
  // Your code here
}

Thanks to you both! That's very helpful.

Glad to have helped! :wink:

Is there any way to scroll the focussed text component to the top of the page? I believe this should be a natural next step for most forms.

Something like this?

  _myOnFocusFunction (componentName) {
    if (componentName) {
      var component = this.refs.form1.getComponent(componentName)
      this.refs._requestScrollView.scrollTo({y: component.height})
    }
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

muthuraman007 picture muthuraman007  路  4Comments

pocesar picture pocesar  路  4Comments

scarlac picture scarlac  路  4Comments

timdoes picture timdoes  路  4Comments

pgmemk picture pgmemk  路  4Comments