Helper
Form
The FormKit helper allows you to manipulate a form and its fields through a clear and expressive API.
Example
import formKit from "discourse/tests/helpers/form-kit";
test("fill in input", async function (assert) {
await render(<template>
<Form class="my-form" as |form data|>
<form.Field @name="foo" as |field|>
<field.Input />
</form.Field>
</Form>
</template>);
const myForm = formKit(".my-form");
});
submit()
Submits the associated form.
Example
formKit().submit();
reset()
Resets the associated form.
Example
formKit().reset();
Field
Parameters
name
(string): The name of the field.
fillIn()
Can be used on <field.Input @type="text" />
, <field.Code />
, <field.Textarea />
, and <field.Composer />
.
Parameters
value
(string | integer | undefined): The value to set on the input.
Example
await formKit().field("foo").fillIn("bar");
toggle()
Can be used on <field.Checkbox />
, <field.Toggle />
or <field.Password />
Will toggle the state of the control. In the case of the password control it will actually toggle the visibility of the field.
Example
await formKit().field("foo").toggle();
accept()
Can be used on <field.Checkbox />
.
Example
await formKit().field("foo").accept();
refuse()
Can be used on <field.Checkbox />
.
Example
await formKit().field("foo").refuse();
select()
Can be used on <field.Select />
, <field.Menu />
, <field.Icon />
, and <field.RadioGroup />
.
Will select the given value.
Parameters
value
(string | integer | undefined): The value to select.
Example
await formKit().field("foo").select("bar");