feat: support for labelPosition, radio/checkboxed checked value
This commit is contained in:
parent
0b286eba11
commit
5d83965c0c
3 changed files with 23 additions and 5 deletions
|
@ -1,12 +1,24 @@
|
||||||
---
|
---
|
||||||
import {FormGroup} from './form-group';
|
import {FormGroup} from './form-group';
|
||||||
|
export interface Props {
|
||||||
|
formGroup: FormGroup;
|
||||||
|
}
|
||||||
|
|
||||||
const form: FormGroup = Astro.props.formGroup;
|
const form: FormGroup = Astro.props.formGroup;
|
||||||
---
|
---
|
||||||
<form>
|
<form>
|
||||||
{form?.controls?.map(control => (
|
{form?.controls?.map(control => (
|
||||||
<field>
|
<div>
|
||||||
<label for={control.name}>{control.label}</label>
|
{(control.labelPosition === 'left')
|
||||||
<input name={control.name} id={control.name} type={control.type} value={control.value} />
|
? <label for={control.name}>{control.label}</label>
|
||||||
</field>
|
: null}
|
||||||
|
|
||||||
|
<input name={control.name} id={control.name} type={control.type} value={control.value} checked={control.value==='checked'} />
|
||||||
|
|
||||||
|
{(control.labelPosition === 'right')
|
||||||
|
? <label for={control.name}>{control.label}</label>
|
||||||
|
: null}
|
||||||
|
|
||||||
|
</div>
|
||||||
))}
|
))}
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -3,4 +3,5 @@ export class FormControl {
|
||||||
type?: 'text' | 'checkbox' | 'radio' = 'text'; // add more
|
type?: 'text' | 'checkbox' | 'radio' = 'text'; // add more
|
||||||
value?: string | number | null | string[];
|
value?: string | number | null | string[];
|
||||||
label?: string;
|
label?: string;
|
||||||
|
labelPosition?: 'right' | 'left' = 'left';
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,11 @@ export class FormGroup {
|
||||||
controls: FormControl[];
|
controls: FormControl[];
|
||||||
|
|
||||||
constructor(controls: FormControl[]) {
|
constructor(controls: FormControl[]) {
|
||||||
this.controls = controls;
|
this.controls = controls.map(control => (
|
||||||
|
{
|
||||||
|
...control,
|
||||||
|
labelPosition: control.labelPosition || 'left'
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue