I am making dynamic UI, Getting response from backend and according to that making UI.
dynamicFormConfig is a object , inside there is 3 arrays , likes at 1st index
name: “Passport”, code: “passport”, visible: false, isSelected: false, property: Array(10)}
again inside there is property array whihc has some value .And in below code I am mapping
property array and making UI, this is one piece of code .
Now there will be multiple value in property as its dynamic , so I have to store the values dynamically .
So in below code “onChangeText” I was to update the field value which is inside the Property and then updated array I’ll store in redux
dynamicFormConfig: {individualIdentification: Array(3)}
dynamicFormConfig:
individualIdentification: Array(3)
0: {name: "Civil ID", code: "civilId", visible: true, isSelected: true, property: Array(1)}
1: {name: "Passport", code: "passport", visible: false, isSelected: false, property: Array(10)}
2: {name: "GCC", code: "GCC", visible: true, isSelected: false, property: Array(1)}
1:
code: "passport"
isSelected: false
name: "Passport"
property: Array(10)
0:
errorMessage: {pattern: "Enter Alpha characters only", required: "First Name is Required"}
id: "passportNumber"
label: "ID"
masterDataVal: ""
maxLength: ""
pattern: "^{0,8}"
placeholder: "Enter Passport Number"
required: true
title: "Passport Number"
type: "string"
value: ""
visible: true
const {individualIdentification } = useSelector((state) => state.authUser.dynamicFormConfig);
let dynamciPass= individualIdentification.filter(item=>item.code==="passport")
{dynamciPass[0].property.map((item,index) => (
<View>
{item.type==='string' &&
<View style={{ marginTop: 20 }}>
<TextLight>{t(item.label)}</TextLight>
<TextInput
placeholder={t(item.placeholder)}
onChangeText={(text) => {
if (!/[^a-zA-Zs]/.test(text)) {
// setFullName(text);
// Here I want to update the value fields and then
//dispatch(passportDynamic({ key: item.label, value: text }));
dispatch(setDynamicFormValueUpdate();
}
}}
value={item.value}
style={{
borderBottomColor: colors.grey19,
borderBottomWidth: 0.5,
color: colors.textPrimary,
borderStyle: 'dashed',
...RtlStyles.text,
}}></TextInput>
</View>}