76 lines
1.6 KiB
TypeScript
76 lines
1.6 KiB
TypeScript
namespace formgen
|
|
{
|
|
|
|
/**
|
|
*/
|
|
type type_action = {
|
|
label : string;
|
|
target : string;
|
|
};
|
|
|
|
|
|
/**
|
|
*/
|
|
export class class_form<type_value>
|
|
{
|
|
|
|
/**
|
|
*/
|
|
private input : formgen.input.interface_input<type_value>;
|
|
|
|
|
|
/**
|
|
*/
|
|
private actions : Array<type_action>;
|
|
|
|
|
|
/**
|
|
*/
|
|
public constructor(
|
|
input : formgen.input.interface_input<type_value>,
|
|
actions : Array<type_action>
|
|
)
|
|
{
|
|
this.input = input;
|
|
this.actions = actions;
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
public async setup(
|
|
element_target : Element
|
|
) : Promise<void>
|
|
{
|
|
const element_form : Element = document.createElement("form");
|
|
element_form.classList.add("formgen-form");
|
|
// element_form.setAttribute("method", "POST");
|
|
// input
|
|
{
|
|
const element_input : Element = document.createElement("div");
|
|
element_input.classList.add("formgen-form-input");
|
|
await this.input.setup(element_input);
|
|
element_form.appendChild(element_input);
|
|
}
|
|
// actions
|
|
{
|
|
const element_actions : Element = document.createElement("div");
|
|
element_actions.classList.add("formgen-form-actions");
|
|
for (const action of this.actions)
|
|
{
|
|
const element_action : Element = document.createElement("button");
|
|
element_action.classList.add("formgen-form-button");
|
|
element_action.setAttribute("formaction", action.target);
|
|
element_action.textContent = action.label;
|
|
element_actions.appendChild(element_action);
|
|
}
|
|
element_form.appendChild(element_actions);
|
|
}
|
|
element_target.appendChild(element_form);
|
|
return Promise.resolve<void>(undefined);
|
|
}
|
|
|
|
}
|
|
|
|
}
|