fix(core): update
This commit is contained in:
parent
00cb552f44
commit
7d63f16fc1
@ -7,7 +7,9 @@ import { DeesInputRadio } from './dees-input-radio';
|
||||
import * as domtools from '@designestate/dees-domtools';
|
||||
import { DeesFormSubmit } from './dees-form-submit';
|
||||
|
||||
export type TFormElement = Array<DeesInputCheckbox | DeesInputText | DeesInputQuantitySelector | DeesInputRadio>;
|
||||
export type TFormElement = Array<
|
||||
DeesInputCheckbox | DeesInputText | DeesInputQuantitySelector | DeesInputRadio
|
||||
>;
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
@ -18,15 +20,22 @@ declare global {
|
||||
@customElement('dees-form')
|
||||
export class DeesForm extends DeesElement {
|
||||
public static demo = () => html`
|
||||
<dees-form style="display: block; margin:auto; max-width: 500px; padding: 20px" @formData=${async (eventArg) => {
|
||||
<dees-form
|
||||
style="display: block; margin:auto; max-width: 500px; padding: 20px"
|
||||
@formData=${async (eventArg) => {
|
||||
const form: DeesForm = eventArg.currentTarget;
|
||||
form.setStatus('pending', 'authenticating...');
|
||||
await domtools.plugins.smartdelay.delayFor(1000);
|
||||
form.setStatus('success', 'authenticated!');
|
||||
}}>
|
||||
}}
|
||||
>
|
||||
<dees-input-text .required="${true}" key="hello1" label="a text"></dees-input-text>
|
||||
<dees-input-text .required="${true}" key="hello2" label="also a text"></dees-input-text>
|
||||
<dees-input-checkbox .required="${true}" key="hello3" label="another text"></dees-input-checkbox>
|
||||
<dees-input-checkbox
|
||||
.required="${true}"
|
||||
key="hello3"
|
||||
label="another text"
|
||||
></dees-input-checkbox>
|
||||
<dees-form-submit>Submit</dees-form-submit>
|
||||
</dees-form>
|
||||
`;
|
||||
@ -63,7 +72,11 @@ export class DeesForm extends DeesElement {
|
||||
const formChildren: TFormElement = [];
|
||||
|
||||
for (const child of children) {
|
||||
if (child instanceof DeesInputCheckbox || child instanceof DeesInputText || child instanceof DeesInputQuantitySelector) {
|
||||
if (
|
||||
child instanceof DeesInputCheckbox ||
|
||||
child instanceof DeesInputText ||
|
||||
child instanceof DeesInputQuantitySelector
|
||||
) {
|
||||
formChildren.push(child);
|
||||
}
|
||||
}
|
||||
@ -82,8 +95,7 @@ export class DeesForm extends DeesElement {
|
||||
}
|
||||
|
||||
public async checkRequiredStatus() {
|
||||
console.log('checking the required status.')
|
||||
|
||||
console.log('checking the required status.');
|
||||
|
||||
let requiredOK = true;
|
||||
for (const childArg of this.getFormChildren()) {
|
||||
@ -107,16 +119,19 @@ export class DeesForm extends DeesElement {
|
||||
const valueObject = await this.gatherData();
|
||||
const formDataEvent = new CustomEvent('formData', {
|
||||
detail: {
|
||||
data: valueObject
|
||||
data: valueObject,
|
||||
},
|
||||
bubbles: true
|
||||
bubbles: true,
|
||||
});
|
||||
this.dispatchEvent(formDataEvent);
|
||||
console.log('dispatched data:')
|
||||
console.log('dispatched data:');
|
||||
console.log(valueObject);
|
||||
}
|
||||
|
||||
public setStatus (visualStateArg: 'normal' | 'pending' | 'error' | 'success', textStateArg: string) {
|
||||
public setStatus(
|
||||
visualStateArg: 'normal' | 'pending' | 'error' | 'success',
|
||||
textStateArg: string
|
||||
) {
|
||||
const inputChildren = this.getFormChildren();
|
||||
const submitButton = this.getSubmitButton();
|
||||
|
||||
@ -135,9 +150,15 @@ export class DeesForm extends DeesElement {
|
||||
inputChild.disabled = true;
|
||||
}
|
||||
break;
|
||||
case 'error':
|
||||
submitButton.disabled = true;
|
||||
submitButton.status = 'error';
|
||||
for (const inputChild of inputChildren) {
|
||||
inputChild.disabled = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
submitButton.text = textStateArg;
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user