T
T
TaTIk942016-09-25 16:21:59
Java
TaTIk94, 2016-09-25 16:21:59

Does not check the text for blurring?

I made a condition for checking, but for some reason the final method only works, so you can send with 2 empty lines, but I need all three lines to be checked, what is the error?

if (textname.getText().length() == 0){
            textname.setError("Заполните Пустое Поле");
        }
        if (textsoname.getText().length() == 0){
            textsoname.setError("Заполните Пустое Поле");
        }
        if (texttel.getText().length() == 0){
            texttel.setError("Заполните Пустое Поле");
        }

        else {
//и если все поля заполнены применить этот метод

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sn0wSky, 2016-09-25
@TaTIk94

Because your "else" only applies to the last if
Do this:

var errors = false;
if (textname.getText().length() == 0){
     textname.setError("Заполните Пустое Поле");
     errors = true;
}
if (textsoname.getText().length() == 0){
     textsoname.setError("Заполните Пустое Поле");
     errors = true;
}
if (texttel.getText().length() == 0){
     texttel.setError("Заполните Пустое Поле");
     errors = true;
}


if(!errors){ /* все поля заполнены */ }

S
shell1989, 2016-09-25
@shell1989

try writing this again:
if (texttel.getText().length() == 0){
texttel.setError("Fill Empty Field");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question