I am trying to start loading my forms re-actively from a database, with all the data for the controls stored in the database (MySQL).
I have an interface for the controls that looks like this:
export class IFormControl {
type: string;
label: string;
name: string;
value?: string;
disabled?: boolean;
placeholder?: string;
validation?: [];
options?: [];
}
And and example of what this should look like in my component after getting the info from the db:
{
type: 'input',
label: 'Full name',
name: 'name',
placeholder: 'Enter your name',
validation: [Validators.required, Validators.minLength(4)],
disabled: false
}
Everything is fine except I am not sure what would be the best way to store my validation rules?
At the moment I am thinking of just taking the whole line, tuning it into a string, and storing it as such in a db 'text' field. Then when I retrieve it back, I would get the string 'Validators.required, Validators.minLength(4)', and just push the string into an array ['Validators.required, Validators.minLength(4)'], and then with regex strip off all the quotation marks [Validators.required, Validators.minLength(4)]
Would this be the best way, or is there a better way to store and fetch the validators?