<pwc-dynamic-form>
<pwc-dynamic-form-content> </pwc-dynamic-form-content>
<pwc-dynamic-form-buttons> </pwc-dynamic-form-buttons>
</pwc-dynamic-form>
<form>
<slot />
</form>
formChanged: EventEmitter<PwcDynamicForm.FormChangedEventPayload>
Emitted when there is a change in the form.
A change can be a field change or a form reset.
type: "change" | "reset";
fieldChangedEventPayload: FieldChangedEventPayload;
formResetEvent: Event;
formValues: { [key: string]: boolean | string | string[] };
formElement: HTMLPwcDynamicFormElement;
type
: type of the change.change
if the event is raised due to a field change.reset
if the event is raised due to a form reset.fieldChangedEventPayload
: (valid if type ischange
) payload of thefieldChangedEvent
that caused this event to be raised.formResetEvent
: (valid if type isreset
) thereset
event that caused this event to be raised.formValues
: current form values (not the values before the event, but the new ones).formElement
: the<pwc-dynamic-form>
element.
async getFieldValues(returnOnlyValuesForPwcSelects: boolean = false): Promise<{ [key: string]: boolean | string | string[] }>
returnOnlyValuesForPwcSelects
: Optional, defaults to false. If true, the values ofpwc-choices
fields will be object arrays containing choice objects, as passed to the items configuration. If false, they will be string arrays containing only values of each choice object.
<div>
Generated fields
</div>
items: string | PwcDynamicForm.ContentItemConfig[]
This prop is our configuration for the form fields.
dynamicFormContent.items = [
{
type: "select-single",
name: "single-select-1",
id: "single-select-1",
label: "This is a label!",
distinct: "value",
choices: [
{
value: "superstar",
label: "Superstar"
},
{
value: "foo",
label: "bar"
}
]
},
{
type: "checkbox",
name: "checkbox_1",
id: "checkbox_1",
label: "This is another label!"
}
];
type ContentItemConfig = NativeInputConfig | PwcSelectConfig | PwcColorPickerConfig
This type is a union of the supported interfaces for the fields.
export interface NativeInputConfig
extends JSXBase.InputHTMLAttributes<HTMLInputElement> {
label: string;
}
This interface is used for native HTML input fields.
label
: Translated into a<label>
element for our generated element.
You can also pass in all valid HTML attributes of an <input>
tag, alongside the custom fields listed above.
export interface PwcSelectConfig
extends JSXBase.InputHTMLAttributes<HTMLPwcChoicesElement> {
type: "select-single" | "select-multiple" | "select-text";
label: string;
choices: Array<any>;
distinct?: "value" | "label" | "all" | "none";
}
This interface is used for pwc-choices
web components.
-
type
: The type of the generatedpwc-choices
web component. Mapping:select-single
->single
select-multiple
->multiple
select-text
->text
-
label
: Translated into a<label>
element for our generated element. -
choices
: The array of choice objects for this element. A usual choice object looks like this:
{
label: "Superstar",
value: "superstar",
selected: false, // optional
disabled: false, // optional
/* any other custom field you wish can also be passed */
}
distinct
: (optional) The type of distinct filter to be applied to the choices. See: pwc-choices documentation.
You can also pass in all valid HTML attributes of an <pwc-choices>
tag, alongside the custom fields listed above.
export interface PwcColorPickerConfig
extends JSXBase.InputHTMLAttributes<HTMLPwcColorPickerElement> {
label: string;
}
This interface is used for pwc-color-picker
web components.
You can pass in all valid HTML attributes of a <pwc-color-picker>
tag. The label field is translated into a <label>
element for our generated element.
fieldChanged: EventEmitter<PwcDynamicForm.FieldChangedEventPayload>
This event is emitted whenever a field changes.
element: HTMLInputElement | HTMLPwcChoicesElement | HTMLPwcColorPickerElement;
newValue: string | string[];
originalEvent: Event | CustomEvent;
element
: The form element that changed.newValue
: The new value of the element that changed.originalEvent
: The original event that caused this event to be raised.
The type of the generated element is determined with the type
field in the element's configuration object, in items
prop:
color
-><pwc-color-picker>
select-single
-><pwc-choices>
with single select config.select-multiple
-><pwc-choices>
with multiple select config.select-text
-><pwc-choices>
with text select config.- Any other
type
-><input type="__TYPE__">
The final generated structure will look like this:
<div class="form-group">
<label>
Label
<__GENERATED ELEMENT__></__GENERATED ELEMENT__>
</label>
</div>
Note: Placement of the label text depends on the generated element type.
Item config:
{
type: "select-single",
name: "ss1-name",
id: "ss1-id",
label: "ss1-label",
distinct: "value",
choices: [
{
value: "superstar",
label: "Superstar",
selected: false,
disabled: false
},
{
value: "foo",
label: "bar",
selected: false,
disabled: false
}
]
}
Generated element:
<div class="form-group">
<label>
ss1-label
<pwc-choices
type="single"
name="ss1"
id="ss1"
distinct="value"
choices='[
{
"value": "superstar",
"label": "Superstar",
"selected": false,
"disabled": false
},
{
"value": "foo",
"label": "bar",
"selected": false,
"disabled": false
}
]'
></pwc-choices>
</label>
</div>
Item config:
{
type: "number",
name: "number-input-name",
id: "number-input-id",
label: "This is a number input!",
required: true
}
Generated element:
<div class="form-group">
<label>
This is a number input!
<input
type="number"
name="number-input-name"
id="number-input-id"
required
></input>
</label>
</div>
- For
color
andcheckbox
types, the label text is placed after the input element.
- More items will be supported soon, and we plan on implementing an interface, which you can use to add support for your own custom elements.
<div>
Generated buttons
</div>
items: string | PwcDynamicForm.ButtonItemConfig[]
This prop is our configuration for the form fields.
ButtonItemConfig = JSXBase.InputHTMLAttributes<HTMLInputElement>
You can pass in any valid attribute of an html <input>
tag to an object of this type.
The given config object for the button is simply translated into <input {...config}></input>
.
Item config:
{
type: "submit",
id: "foo",
name: "bar"
}
Generated button:
<input type="submit" id="foo" name="bar"></input>