jb-form
Version:
form web component with extended feature like validation and dirty check
46 lines (45 loc) • 1.54 kB
text/typescript
import { FormExtractFunction, FormValues, JBFormWebComponent, TraverseResult } from "./jb-form";
export class SubFormList {
get list() {
return [...this.
}
get dictionary(){
return Object.freeze({...this.
}
setValues<TFormValue extends FormValues = FormValues>(value: TFormValue){
for (const subForm of this.
if (subForm.name && value[subForm.name] !== undefined) {
subForm.setFormValues(value[subForm.name],false);
}
}
}
setInitialValues<TFormValue extends FormValues = FormValues>(value: TFormValue){
for (const subForm of this.
if (subForm.name && value[subForm.name] !== undefined) {
subForm.setFormInitialValues(value[subForm.name],false);
}
}
}
traverse<T>(extractFunction: FormExtractFunction<T>): TraverseResult<T> {
type ValueType = ReturnType<typeof extractFunction>;
const result: TraverseResult<ValueType> = {};
//make it partial so every callback function have to check for nullable properties
for (const formElement of this.
if (formElement.name) {
result[formElement.name] = extractFunction(formElement);
}
}
return result;
}
add(form:JBFormWebComponent){
if(this.
return;
}
this.
if(form.name){
this.
}
}
}