Need help in Dynamic Form Group child control validation
ahavagowtham opened this issue · 2 comments
ahavagowtham commented
Hi,
export interface DummyModel {
line?: { [id: string]: Line };
}
export interface Line {
lineNo: number;
unit: number;
title: string;
}
export const validateNetworkFlightDetailForm = updateGroup<DummyModel>({
line: (state, parentState) => {
const updates = Object.keys(state.controls).reduce((acc, key) => {
acc[key] = validate(required);
return acc;
}, {} as StateUpdateFns<DummyModel['line']>);
return updateGroup(state, updates);
},
});
My validation logic validates the whole line. I am not able to validate the inner controls of line. For example
lineNo:validate(required). Something like this. Any help would be appreciated.
MrWolfZ commented
What you are doing is almost correct. Instead of acc[key] = validate(required);
do acc[key] = updateGroup<Line>({ lineNo: validate(required) });
.
Let me know if this works, otherwise I'll take a deeper look at your example.
ahavagowtham commented
Thanks a lot sir. It worked. You just saved my day.