feat: initial form control state (#60)
* Form control tries * feat: implement form-control state * fix: organize client methods * fix(client): return undefined instead of throwing error * fix: fix exports and lint * fix: Change implementation of setting isPristine with proxy
This commit is contained in:
parent
f164bdfb6a
commit
2fd25b7d93
4 changed files with 15 additions and 12 deletions
|
@ -27,14 +27,6 @@ form.controls.push(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
//insert submit button
|
|
||||||
form.controls.push(
|
|
||||||
new FormControl({
|
|
||||||
type: "submit",
|
|
||||||
name: "submit",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// get the FormControl object
|
// get the FormControl object
|
||||||
const userNameControl = form.get("username");
|
const userNameControl = form.get("username");
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,16 @@ const getFormControl = (name: string) => {
|
||||||
value = formControl.value === 'checked' ? '' : 'checked';
|
value = formControl.value === 'checked' ? '' : 'checked';
|
||||||
}
|
}
|
||||||
formControl.setValue(value);
|
formControl.setValue(value);
|
||||||
formControl.setIsPristine(false);
|
formControl.isPristine = false;
|
||||||
});
|
});
|
||||||
return formControl;
|
|
||||||
|
const controlProxy = new Proxy(formControl, {
|
||||||
|
set() {
|
||||||
|
//prevent any setter to be able to work in client;
|
||||||
|
console.error('Setting this property manually is prohibited!');
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return controlProxy;
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,6 +55,10 @@ export class FormControl {
|
||||||
return this._isPristine;
|
return this._isPristine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set isPristine(value: boolean) {
|
||||||
|
this._isPristine = value;
|
||||||
|
}
|
||||||
|
|
||||||
get isValid() {
|
get isValid() {
|
||||||
return this._isValid;
|
return this._isValid;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import Form from './Form.astro';
|
import Form from './Form.astro';
|
||||||
export default Form;
|
export default Form;
|
||||||
export * from './core/form-control-types';
|
|
||||||
export * from './client';
|
|
||||||
export * from './Form.astro';
|
export * from './Form.astro';
|
||||||
|
|
Loading…
Reference in a new issue