question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MaterialTextField can't set text property

See original GitHub issue

🐛 Bug Report

You can’t set the text value of the MaterialTextField, it crashes the APP. This doesn’t happen in the Simulator. Bug happening in iPhone 6S 13.3.1 and with either XF.Material 1.6.0 or 1.5.8

Expected behavior

The text value of the MaterialTextField changes.

Reproduction steps

Created a new blank Xamarin Forms solution. MainPage.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:ui="clr-namespace:XF.Material.Forms.UI;assembly=XF.Material"
             mc:Ignorable="d"
             x:Class="App1.MainPage">

    <StackLayout>
        <!-- Place new controls here -->
        <ui:MaterialTextField x:Name="txt1"></ui:MaterialTextField>
    </StackLayout>

</ContentPage>

MainPage.xaml.cs

public MainPage()
        {
            InitializeComponent();
            new Thread(new ThreadStart(() =>
            {
                Thread.Sleep(2000);
                txt1.Text = "ofdfk";
            }));
        }

Configuration

Version: 1.x

Platform:

  • 📱 iOS
  • 🤖 Android
  • 🏁 WPF
  • 🌎 UWP
  • 🍎 MacOS
  • 📺 tvOS
  • 🐒 Xamarin.Forms

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mr-rikhambacommented, May 29, 2020
We recently started getting this issue, not sure why now all of a sudden, but based on forum search it might be related to a Xamar.iOS update. So with some guidance from other users in the forum I fixed it like this:

`       
private void SetTextFieldValues(List<MaterialSetter> controls)
{
Device.BeginInvokeOnMainThread(() =>
{
controls.ForEach(x =>
{
x.MaterialTextField.Focus();
Thread.Sleep(100);
x.MaterialTextField.SetBinding(MaterialTextField.TextProperty, new Binding($"BindingContext.{x.Value}", source: this));
//x.MaterialTextField.Unfocus();
});

controls.FirstOrDefault().MaterialTextField.Focus();
});
}
class MaterialSetter
{

public MaterialSetter(MaterialTextField materialTextField, string value)
{
MaterialTextField = materialTextField;
Value = value;
}

public MaterialTextField MaterialTextField { get; }
public string Value { get; }
}
`

And this is how I call it:
`            
SetTextFieldValues(new List<MaterialSetter>
{
new MaterialSetter(FullName, "Details.FullNames"),

});
`
0reactions
martijn00commented, Aug 24, 2020

@pedroreglero can you make a PR with the fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

I can't edit Text Field in Material-UI
In this example I used state for storing current text field value. I see, that you use props for that, but the principle...
Read more >
Text fields - Material Design
Text fields let users enter, edit, and select text. ... not able to read, you should set a content description via the app:errorContentDescription...
Read more >
TextField class - material library - Dart API
A Material Design text field. A text field lets the user enter text, either with hardware keyboard or with an onscreen keyboard. The...
Read more >
TextField API - Material UI
The TextField is a convenience wrapper for the most common cases (80%). It cannot be all things to all people, otherwise the API...
Read more >
React Text Field component - Material UI
The multiline prop transforms the text field into a TextareaAutosize element. Unless the rows prop is set, the height of the text field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found