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:
Fazza Razaq Amiarso 2022-10-07 12:35:01 +07:00 committed by GitHub
parent f164bdfb6a
commit 2fd25b7d93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 12 deletions

View file

@ -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");

View file

@ -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;
}; };

View file

@ -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;
} }

View file

@ -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';