Skip to content

Commit dcc0b00

Browse files
committed
added a new field attribute called name
1 parent a08d7f5 commit dcc0b00

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

app/src/main/res/raw/form.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Type": "TextField",
99
"Tag": "name",
1010
"Hint": "Name",
11+
"Name": "Name",
1112
"Text": "Ahmed",
1213
"Weight": 5,
1314
"ValidationRule": {
@@ -18,6 +19,7 @@
1819
"Type": "TextField",
1920
"Tag": "Age",
2021
"Hint": "Age",
22+
"Name": "Age",
2123
"Text": "5",
2224
"Weight": 5,
2325
"InputType": "Number",

formview/src/main/java/com/seed/widgets/formview/Form.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ data class Row(val fields: List<Field>)
77
data class Field(
88
val type: Type,
99
val text: String,
10+
val name: String,
1011
val tag: String?,
1112
val hint: String,
1213
val weight: Int?,

formview/src/main/java/com/seed/widgets/formview/FormView.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class FormView @JvmOverloads constructor(
286286
field: Field
287287
) {
288288

289-
val errorMandatory = "${field.tag} is mandatory"
289+
val errorMandatory = "${field.name} is mandatory"
290290

291291
val lengthSatisfied = maxMinLengthSatisfied(validationRule, value, field)
292292
if (lengthSatisfied != null)
@@ -331,13 +331,13 @@ class FormView @JvmOverloads constructor(
331331
validationRule.maxValue != 0 -> {
332332
val range = IntRange(validationRule.minValue, validationRule.maxValue)
333333
if (value.toInt() !in range)
334-
"${field.tag} should be between ${validationRule.minValue} and ${validationRule.maxValue}"
334+
"${field.name} should be between ${validationRule.minValue} and ${validationRule.maxValue}"
335335
else
336336
null
337337
}
338338
validationRule.minValue > 0 -> {
339339
if (value.toInt() < validationRule.minValue)
340-
"${field.tag} cannot be less than ${validationRule.minValue}"
340+
"${field.name} cannot be less than ${validationRule.minValue}"
341341
else
342342
null
343343
}
@@ -355,13 +355,13 @@ class FormView @JvmOverloads constructor(
355355
validationRule.maxLength != 0 -> {
356356
val range = IntRange(validationRule.minLength, validationRule.maxLength)
357357
if (value.length !in range)
358-
"${field.tag} should have characters between ${validationRule.minLength} and ${validationRule.maxLength}"
358+
"${field.name} should have characters between ${validationRule.minLength} and ${validationRule.maxLength}"
359359
else
360360
null
361361
}
362362
validationRule.minLength > 0 -> {
363363
if (value.length < validationRule.minLength)
364-
"${field.tag} should have more characters than ${validationRule.minLength}"
364+
"${field.name} should have more characters than ${validationRule.minLength}"
365365
else
366366
null
367367
}

0 commit comments

Comments
 (0)