From 18046045353fe28a6c80eca1f2ad95acea0609ed Mon Sep 17 00:00:00 2001 From: rigo9412 Date: Wed, 6 Feb 2019 18:55:34 -0600 Subject: [PATCH] fix problem validation1.2 --- .../rigoberto/formulatorexample/MainActivity.kt | 6 +++--- .../rigo/ramos/formslibrary/model/FieldText.kt | 16 ++++++++-------- .../ramos/formslibrary/views/FormFragment.kt | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/rigoberto/formulatorexample/MainActivity.kt b/app/src/main/java/com/rigoberto/formulatorexample/MainActivity.kt index 9602643..58db8bf 100644 --- a/app/src/main/java/com/rigoberto/formulatorexample/MainActivity.kt +++ b/app/src/main/java/com/rigoberto/formulatorexample/MainActivity.kt @@ -17,8 +17,8 @@ class MainActivity : AppCompatActivity() { setContentView(R.layout.activity_main) btnForm.setOnClickListener { - val field1 = FieldImage(arrayListOf("nombre"),"Nombre*",true,"Campo requerido", TypeField.SELECT_IMAGE) - val field2 = FieldText(arrayListOf("hora"),"Hora de entrega*",true, TypeField.TEXT_HOURS,"Campo requerido") + //val field1 = FieldImage(arrayListOf("nombre"),"Nombre*",false,"Campo requerido", TypeField.SELECT_IMAGE) + val field2 = FieldText(arrayListOf("hora"),"Hora de entrega*",false, TypeField.TEXT_HOURS,"Campo requerido") val fieldTipoFlotilla = FieldOptions(arrayListOf("tipoFlotilla"),"Tipo flotilla",TypeField.SELECT_OPTION, arrayListOf("1","2","3"), arrayListOf()) @@ -26,7 +26,7 @@ class MainActivity : AppCompatActivity() { val field3 = FieldText(arrayListOf("apellido_paterno"),"Apellido Paterno*",true, TypeField.TEXT,"Campo requerido",140) val field32 = FieldText(arrayListOf("apellido_paterno"),"Apellido Paterno*",true, TypeField.TEXT,"Campo requerido",140) //val field3 = Field(arrayListOf("apellido_materno"),"Apellido Materno*",true, TypeField.TEXT,"Campo requerido",140) - val form = Form("1","Informacion Personal", arrayListOf(field1,field2,fieldTipoFlotilla,field3,field32)) + val form = Form("1","Informacion Personal", arrayListOf(field2,fieldTipoFlotilla,field3)) val i = Intent(this, FormsActivity::class.java) diff --git a/formslibrary/src/main/java/com/rigo/ramos/formslibrary/model/FieldText.kt b/formslibrary/src/main/java/com/rigo/ramos/formslibrary/model/FieldText.kt index e4cdfd9..cb433a4 100644 --- a/formslibrary/src/main/java/com/rigo/ramos/formslibrary/model/FieldText.kt +++ b/formslibrary/src/main/java/com/rigo/ramos/formslibrary/model/FieldText.kt @@ -322,15 +322,15 @@ open class FieldText() : Field(){ return true return when(type){ - TypeField.TEXT-> !(value?.get(0)!!.isNotEmpty()) - TypeField.TEXT_EMAIL-> !(value?.get(0)!!.isNotEmpty())&& isEmailValid(value?.get(0)!!) + TypeField.TEXT-> (value?.get(0)!!.isNotEmpty()) + TypeField.TEXT_EMAIL-> (value?.get(0)!!.isNotEmpty())&& isEmailValid(value?.get(0)!!) TypeField.TEXT_PASSWORD-> !(value?.get(0)!!.isNotEmpty()) && isValidPassword(value?.get(0)!!) - TypeField.TEXT_NUM-> !(value?.get(0)!!.isNotEmpty()) - TypeField.TEXT_HOURS-> !(value?.get(0)!!.isNotEmpty()) - TypeField.TEXT_DEC-> !(value?.get(0)!!.isNotEmpty()) - TypeField.TEXT_PHONE-> !(value?.get(0)!!.isNotEmpty()) - TypeField.TEXT_CURP-> !((value?.get(0)!!.isNotEmpty()) && isValidCURP(value?.get(0)!!)) - TypeField.TEXT_RFC-> !((value?.get(0)!!.isNotEmpty()) && isValidRFC(value?.get(0)!!)) + TypeField.TEXT_NUM-> (value?.get(0)!!.isNotEmpty()) + TypeField.TEXT_HOURS-> (value?.get(0)!!.isNotEmpty()) + TypeField.TEXT_DEC-> (value?.get(0)!!.isNotEmpty()) + TypeField.TEXT_PHONE-> (value?.get(0)!!.isNotEmpty()) + TypeField.TEXT_CURP-> ((value?.get(0)!!.isNotEmpty()) && isValidCURP(value?.get(0)!!)) + TypeField.TEXT_RFC-> ((value?.get(0)!!.isNotEmpty()) && isValidRFC(value?.get(0)!!)) else -> { return true } diff --git a/formslibrary/src/main/java/com/rigo/ramos/formslibrary/views/FormFragment.kt b/formslibrary/src/main/java/com/rigo/ramos/formslibrary/views/FormFragment.kt index 8046683..b01bc50 100644 --- a/formslibrary/src/main/java/com/rigo/ramos/formslibrary/views/FormFragment.kt +++ b/formslibrary/src/main/java/com/rigo/ramos/formslibrary/views/FormFragment.kt @@ -275,7 +275,7 @@ class FormFragment : Fragment() { TypeField.TEXT_PHONE, TypeField.TEXT_PASSWORD, TypeField.TEXT_DATE,TypeField.TEXT_RFC,TypeField.TEXT_CURP -> { if (view is TextInputLayout) { form!!.fields[index].value?.add(0,view.editText?.text.toString()) - if (form!!.fields[index].isValid()) { + if (!form!!.fields[index].isValid()) { view.error = form!!.fields[index].errorMessage isValid = false }else{