Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change textfield content #205

Open
Flow-Flinc opened this issue Nov 29, 2019 · 6 comments
Open

Change textfield content #205

Flow-Flinc opened this issue Nov 29, 2019 · 6 comments

Comments

@Flow-Flinc
Copy link

I want to update the textfield content from outside, so I give in a new value into field value.
But the component don't accept the new content.

I forked the code and removed the state of the field value and ask if this is a feature you want to have on your main branch?

https://github.com/Flow-Flinc/react-native-material-textfield

@karanpratapsingh
Copy link

I just faced this issue, I think this can be resolved by using a .setValue method via ref as mentioned in docs

@ajinkyadesai-git
Copy link

ajinkyadesai-git commented Dec 20, 2019

value is not getting set when i pass prop, value={this.state.customerList}

Edit: Able to set through

  1. ref={ref => { this.customerName = ref; }}
  2. this.customerName.setValue( );

@vandero
Copy link

vandero commented Apr 1, 2020

Hi, I am seeing the same problem. Updating a bound state variable does not rerender the text contents. I don't think it should be necessary to create a ref for each and every textfield used.

@hmolotsi
Copy link

@vandero I agree...what might work for you is to wrap this component so that you can call setValue when the component updates:

import React, {
  Component
} from 'react';

import {
  TextField,
} from 'react-native-material-textfield';

export class MyTextField extends Component {
  constructor(props) {
    super(props);
  }

  componentDidUpdate(prevProps) {
    if ( this.props.value !== prevProps.value ) {
      this.textFieldRef.setValue(this.props.value);
    }
  }

  render() {
    return (
      <TextField
        {...this.props}
        ref={reference => { this.textFieldRef = reference }}
      />
    );
  }
}

@nadav2051
Copy link

It happens because getDerivedStateFromProps prevents it from updating.

I opened a pull request to address this issue.

#278

@sagormax
Copy link

sagormax commented Nov 16, 2023

value is not getting set when i pass prop, value={this.state.customerList}

Edit: Able to set through

  1. ref={ref => { this.customerName = ref; }}
  2. this.customerName.setValue( );

For functional component:
<OutlinedTextField ref={ref => ref?.setValue(nameValue || '') } />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants