1
votes

I followed the instructions here to bind my view model validation to the input form. Using MVVMCross to bind to error messages

The problem I have now is that there is a lot of extra spacing on the form due to the validation elements. How do I make these spacing problems go away? It's a bit difficult to use a Visibility converter due to the fact there is no property for each field. Same problem with Android and iOS. I suppose maybe some sort of custom visibility converter?

1
Can you just bind Visible Errors['Email'] ? I think that should work - although for IOS you'll need to use constraints to resize the layout. - Stuart
Visible Errors['Email'] does not work, the fields stay invisible constantly. I know the field binding works because Text Errors['Email'] does update the field when an error exists. - Ryan Langton

1 Answers

4
votes

I think a quick fix might be to use a binding like Visible Errors['Email'] - however, you're reporting that's not working (so transferred that to https://github.com/MvvmCross/MvvmCross/issues/494 - thanks)

Since that doesn't work directly, then you you should be able to bind the Visible boolean property using something like (in Android):

<TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:textColor="#ff0000"
  android:text="My error text"
  local:MvxBind="Visible ErrorExists(Errors['Email'],FallbackValue=null)"
    />

where ErrorExists is:

public class ErrorExistsValueConverter : MvxValueConverter
{
    public override object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return (value != null);
    }
}

For iOS, if you are showing/hiding UIViews, then you would need to ensure your UI layout auto-updates - e.g. using constraints


As an alternative UI technique, you should also be able to use binding on the background color of an EditText - similar to the color binding in https://github.com/MvvmCross/MvvmCross-Tutorials/blob/master/ValueConversion/ValueConversion.UI.Droid/Resources/Layout/View_Colors.axml