vekexasia / android-edittext-validator

Android form edit text is an extension of EditText that brings data validation facilities to the edittext.
MIT License
1.45k stars 378 forks source link

Error string/exclamation mark not showing on validation fail #49

Open asknask opened 8 years ago

asknask commented 8 years ago

I have the FormEditText wrapped in the TextInputLayout class if that matters.

Whenever I test the validation, the error or the exclamation mark don't show. I have to manually focus the culprit field to get the error string shown.

This causes a lot of issues as the user doesn't know what the problem is.

Here's the xml:

<android.support.design.widget.TextInputLayout
                android:id="@+id/til_tradingName"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:hint="@string/trading_name">

                <com.andreabaccega.widget.FormEditText
                    android:id="@+id/tradingName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textCapWords"
                    app:testType="nocheck"/>

            </android.support.design.widget.TextInputLayout>
vekexasia commented 8 years ago

That seems strange. Which version of the lib are you usign?

asknask commented 8 years ago

1.3.3.

It is indeed strange. Shall I share my entire xml?

Maybe it has something to do with the fact that I have 4 columns of FormEditTexts on one horizontal layout. If I keep pressing enter to go to the next field, some fields get skipped.

On Sep 30, 2016 9:03 PM, "Andrea Baccega" notifications@github.com wrote:

That seems strange. Which version of the lib are you usign?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vekexasia/android-edittext-validator/issues/49#issuecomment-250784025, or mute the thread https://github.com/notifications/unsubscribe-auth/AMaIfp8quhl2YXJAU0lvq1kUvdggzWbYks5qvTLWgaJpZM4KLBCy .

vekexasia commented 8 years ago

It is probably due to your layout. Did you try to place it out the column layout?

Il 30 set 2016 6:32 PM, "Asim Shahzad" notifications@github.com ha scritto:

1.3.3.

It is indeed strange. Shall I share my entire xml?

Maybe it has something to do with the fact that I have 4 columns of FormEditTexts on one horizontal layout. If I keep pressing enter to go to the next field, some fields get skipped.

On Sep 30, 2016 9:03 PM, "Andrea Baccega" notifications@github.com wrote:

That seems strange. Which version of the lib are you usign?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vekexasia/android-edittext-validator/ issues/49#issuecomment-250784025, or mute the thread https://github.com/notifications/unsubscribe-auth/ AMaIfp8quhl2YXJAU0lvq1kUvdggzWbYks5qvTLWgaJpZM4KLBCy .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vekexasia/android-edittext-validator/issues/49#issuecomment-250790986, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMPS2pZWoig0CBMAE0ZnYWAa_va4Egaks5qvTmvgaJpZM4KLBCy .

asknask commented 8 years ago

On Fri, Sep 30, 2016 at 9:51 PM, Andrea Baccega notifications@github.com wrote:

It is probably due to your layout. Did you try to place it out the column layout?

Il 30 set 2016 6:32 PM, "Asim Shahzad" notifications@github.com ha scritto:

1.3.3.

It is indeed strange. Shall I share my entire xml?

Maybe it has something to do with the fact that I have 4 columns of FormEditTexts on one horizontal layout. If I keep pressing enter to go to the next field, some fields get skipped.

On Sep 30, 2016 9:03 PM, "Andrea Baccega" notifications@github.com wrote:

That seems strange. Which version of the lib are you usign?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vekexasia/android-edittext-validator/ issues/49#issuecomment-250784025, or mute the thread https://github.com/notifications/unsubscribe-auth/ AMaIfp8quhl2YXJAU0lvq1kUvdggzWbYks5qvTLWgaJpZM4KLBCy .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vekexasia/android-edittext-validator/ issues/49#issuecomment-250790986, or mute the thread https://github.com/notifications/unsubscribe-auth/ AAMPS2pZWoig0CBMAE0ZnYWAa_va4Egaks5qvTmvgaJpZM4KLBCy .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vekexasia/android-edittext-validator/issues/49#issuecomment-250795381, or mute the thread https://github.com/notifications/unsubscribe-auth/AMaIfjBjmeJ0qduK8mOTAMvyy1rREDs9ks5qvT4VgaJpZM4KLBCy .

Regards, Asim Shahzad Software Developer Nettech Limited

asknask commented 8 years ago
 <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SalesForm1">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="2">

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal|center_vertical"
            android:orientation="vertical">

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_tradingName"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:hint="@string/trading_name">

                <com.andreabaccega.widget.FormEditText
                    android:id="@+id/tradingName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textCapWords"
                    app:testType="nocheck"/>

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_address"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:hint="@string/address">

                <com.andreabaccega.widget.FormEditText
                    android:id="@+id/address"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textPostalAddress"
                    app:testType="nocheck"/>

            </android.support.design.widget.TextInputLayout>

            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_postcode"
                    android:layout_width="145dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:hint="@string/postcode">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/postcode"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="textCapCharacters"
                        app:testType="nocheck"/>

                </android.support.design.widget.TextInputLayout>

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_phone"
                    android:layout_width="145dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:hint="@string/phone">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/phone"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="phone"
                        app:testType="phone"/>

                </android.support.design.widget.TextInputLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:gravity="center_vertical"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_fax"
                    android:layout_width="145dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:hint="@string/fax">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/fax"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="phone"
                        app:testType="phone"/>

                </android.support.design.widget.TextInputLayout>

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_mobile"
                    android:layout_width="145dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:hint="@string/mobile">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/mobile"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="phone"
                        app:testType="phone"/>

                </android.support.design.widget.TextInputLayout>

            </LinearLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_companyName"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:hint="@string/company_name">

                <com.andreabaccega.widget.FormEditText
                    android:id="@+id/companyName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textCapWords"
                    app:testType="nocheck"/>

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_directorName"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:hint="@string/director_full_name">

                <com.andreabaccega.widget.FormEditText
                    android:id="@+id/directorName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textPersonName"
                    app:testType="personFullName"/>

            </android.support.design.widget.TextInputLayout>

        </LinearLayout>
    </ScrollView>

    <View
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:background="@color/dividerColor"/>

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal|center_vertical"
            android:orientation="vertical">

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_regNo"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:hint="@string/company_reg_no">

                <com.andreabaccega.widget.FormEditText
                    android:id="@+id/regNo"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textCapCharacters"
                    app:testType="nocheck"/>

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/til_clientClassification"
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:hint="@string/client_classification">

                <com.andreabaccega.widget.FormEditText
                    android:id="@+id/clientClassification"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textCapWords"
                    app:testType="nocheck"/>

            </android.support.design.widget.TextInputLayout>

            <CheckBox
                android:id="@+id/checkboxAppointment"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:text="@string/view_by_appointment_only"/>

            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:orientation="horizontal"
                android:gravity="center">

                <CheckBox
                    android:id="@+id/checkboxSMS"
                    android:layout_width="80dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="2dp"
                    android:layout_marginEnd="4dp"
                    android:text="@string/sms"
                    android:layout_gravity="bottom"/>

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_messageCell"
                    android:layout_width="216dp"
                    android:layout_height="wrap_content"
                    android:hint="@string/telephone"
                    android:visibility="gone">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/messageCell"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="phone"
                        app:testType="phone"/>

                </android.support.design.widget.TextInputLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_maxcars"
                    android:layout_width="145dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:hint="@string/maximum_cars">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/maxcars"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="number"
                        app:testType="numeric"/>

                </android.support.design.widget.TextInputLayout>

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_carInitials"
                    android:layout_width="145dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:hint="@string/initials">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/carInitials"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="textCapCharacters"
                        app:testType="nocheck"/>

                </android.support.design.widget.TextInputLayout>

            </LinearLayout>

            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                android:orientation="horizontal">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_dealerships"
                    android:layout_width="145dp"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="5dp"
                    android:hint="@string/no_of_dealerships">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/dealerships"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="number"
                        app:testType="numeric"/>

                </android.support.design.widget.TextInputLayout>

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/til_dealershipInitials"
                    android:layout_width="145dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:hint="@string/initials">

                    <com.andreabaccega.widget.FormEditText
                        android:id="@+id/dealershipInitials"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:inputType="textCapCharacters"
                        app:testType="nocheck"/>

                </android.support.design.widget.TextInputLayout>

            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

<com.dmitrymalkovich.android.ProgressFloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_gravity="bottom|end"
    android:clickable="true">

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/login_24dp"
        app:fabSize="normal"/>

    <ProgressBar
        android:id="@+id/submit_fab_progress"
        style="@style/Widget.AppCompat.ProgressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"/>

</com.dmitrymalkovich.android.ProgressFloatingActionButton>

`

asknask commented 8 years ago

Can this be fixed?

EDIT: A temporary workaround for anyone facing the issue. Modify your for loop for validation. Make it something like this. As soon as the problematic field has focus, the error shows up.

for(FormEditText field : fields)
    {
        if(field.testValidity())
        {
            validation = true;
        }
        else
        {
            validation = false;
            field.requestFocus();
            break;
        }
    }
dimparf commented 7 years ago

The same problem. +1

diandian71 commented 7 years ago

i have same problem i use compile 'com.android.support:design:25.0.1' i see code ,so i find DefaultEditTextValidator--> @Override public void showUIError() { if (mValidator.hasErrorMessage()) { try { TextInputLayout parent = (TextInputLayout) editText.getParent(); parent.setErrorEnabled(true); parent.setError(mValidator.getErrorMessage()); } catch (Throwable e) { editText.setError(mValidator.getErrorMessage()); } } }

should be
TextInputLayout parent = (TextInputLayout) editText.getParentForAccessibility();

vekexasia commented 7 years ago

Can you test It and submit a pull request?

On Dec 12, 2016 3:04 AM, "diandian71" notifications@github.com wrote:

i have same problem i use compile 'com.android.support:design:25.0.1' i see code ,so i find DefaultEditTextValidator--> @Override https://github.com/Override public void showUIError() { if (mValidator.hasErrorMessage()) { try { TextInputLayout parent = (TextInputLayout) editText.getParent(); parent.setErrorEnabled(true); parent.setError(mValidator.getErrorMessage()); } catch (Throwable e) { editText.setError(mValidator.getErrorMessage()); } } }

should be TextInputLayout parent = (TextInputLayout) editText. getParentForAccessibility();

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/vekexasia/android-edittext-validator/issues/49#issuecomment-266327714, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMPSzjTSht4Dyb0Rmh2RLUk3oVSoy2mks5rHKungaJpZM4KLBCy .