[Ugenda Project - Technoforte team] can we have two fields with same field ID #11655
-
SummaryIn business requirements, we need different behaviors in the same field conditionally. Like in the example below, for the FOUNDLING case, we need to add an extra validation for the age
Similarly, there are multiple such requirements, so in a less dependent field we can have two fields with different field ID and we can check both the field values, but in some change where there are high dependencies, like child.dob, or parent idTypes, which are used in E-Signet authentications, we have used the same fieldID for different fields. Here, we are making sure that only one field is rendered in the UI at a time to prevent any leakage. Working exampleconnectToMOSIPIdReader(
{
id: 'child.dob',
analytics: true,
type: 'DATE',
required: true,
secured: true,
validation: [
{
message: {
defaultMessage: 'Must be a valid Birthdate',
description: 'This is the error message for invalid date',
id: 'event.birth.action.declare.form.section.child.field.dob.error'
},
validator: field('child.dob').isBefore().now()
}
],
label: {
defaultMessage: 'Date of birth',
description: 'This is the label for the field',
id: 'event.birth.action.declare.form.section.child.field.dob.label'
},
conditionals: [
{
type: ConditionalType.SHOW,
conditional: field('child.placeOfBirth').inArray([
PlaceOfBirth.HEALTH_FACILITY,
PlaceOfBirth.BARRACK,
PlaceOfBirth.OTHER,
PlaceOfBirth.OUTSIDE_UGANDA
])
}
]
},
{
valuePath: 'data.birthDate',
disableIf: ['pending', 'verified', 'authenticated']
}
),
connectToMOSIPIdReader(
{
id: 'child.dob',
analytics: true,
type: 'DATE',
required: true,
secured: true,
validation: [
{
message: {
defaultMessage: 'Must be a valid Birthdate',
description: 'This is the error message for invalid date',
id: 'event.birth.action.declare.form.section.child.field.foundling.dob.valid.error'
},
validator: field('child.dob').isBefore().now()
},
{
message: {
defaultMessage: 'Foundling child age must be 5 or below 5 years',
description: 'This is the error message for age above 5 years',
id: 'event.birth.action.declare.form.section.child.field.foundling.dob.age.error'
},
validator: not(field('child.dob').isBefore().days(1826).inPast()) // this validation we need extra only for foundling
}
],
label: {
defaultMessage: 'Date of birth',
description: 'This is the label for the field',
id: 'event.birth.action.declare.form.section.child.field.foundling.dob.label'
},
conditionals: [
{
type: ConditionalType.SHOW,
conditional: field('child.placeOfBirth').isEqualTo(
PlaceOfBirth.FOUNDLING
)
}
]
},
{
valuePath: 'data.birthDate',
disableIf: ['pending', 'verified', 'authenticated']
}
),
{
id: 'child.reason',
type: FieldType.SELECT,
options: reasonlateOptions,
required: true,
label: {
defaultMessage: 'Reason for Late registration',
description: 'This is the label for the field',
id: 'event.birth.action.declare.form.section.child.field.reason.label'
},
conditionals: [
{
type: ConditionalType.SHOW,
conditional: and(
not(
field('child.dob') // here we are using the same ID and it's working for both, as at a time only once will be rendered
.isAfter()
.days(applicationConfig.BIRTH.REGISTRATION_TARGET)
.inPast()
),
field('child.dob').isBefore().now(),
not(
field('child.placeOfBirth').isEqualTo(PlaceOfBirth.OUTSIDE_UGANDA)
)
)
}
]
},And if we can use this workaround, is there anything else that we should keep in consideration? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
@Naveen1401 in my opinion, you cannot have 2 fields with the same id. You should have a child.dob and a child.foundlingDob and then deal with that in all other places such as search, dedupe configuration. |
Beta Was this translation helpful? Give feedback.
We don't strictly disallow using 2 fields with the same id (as long as the SHOW conditions are mutually exclusive, the UI won't break), it's just that not all the functionalities have been tested with it (e.g. referring such fields in advanced search, summary page etc.).
On a separate note, the above example can probably be merged together if we use this conditional for validating the foundling age:
which in fact is equivalent to