Skip to content

Commit

Permalink
Merge pull request #2992 from andrewbaldwin44/feature/auth-input-type
Browse files Browse the repository at this point in the history
Add Input Type to Login Form
  • Loading branch information
cyberw authored Nov 19, 2024
2 parents f934691 + f438f71 commit 813f0f2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/developing-locust.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Yarn
$ yarn --version
- Next in web, install all dependencies
- Next, install all dependencies

.. code-block:: console
Expand All @@ -149,9 +149,9 @@ Yarn
Developing
----------

To develop the frontend, run ``yarn dev``. This will start the Vite dev server and allow for viewing and editing the frontend, without needing to a run a locust web server
To develop while running a locust instance, run ``yarn watch``. This will output the static files to the ``dist`` directory. Vite will automatically detect any changed files and re-build as needed. Simply refresh the page to view the changes

To develop while running a locust instance, run ``yarn dev:watch``. This will output the static files to the ``dist`` directory. Vite will automatically detect any changed files and re-build as needed. Simply refresh the page to view the changes
In certain situations (usually when styling), you may want to develop the frontend without running a locust instance. Running ``yarn dev`` will start the Vite dev server and allow for viewing your changes.

To compile the webui, run ``yarn build``

Expand Down
3 changes: 2 additions & 1 deletion docs/extending-locust.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ A full example can be seen `in the auth example <https://github.com/locustio/loc
In certain situations you may wish to further extend the fields present in the auth form. To achieve this, pass a ``custom_form`` dict
to the ``environment.web_ui.auth_args``. In this case, the fields will be represented by a list of ``inputs``, the callback url is
configured by the ``custom_form.callback_url``, and the submit button may optionally be configured using the ``custom_form.submit_button_text``.
The fields in the auth form may be a text, select, checkbox, or secret password field.
The fields in the auth form may be a text, select, checkbox, or secret password field. You may additionally override the HTML input type for
specific field validation (e.g. type=email).

For a full example see `configuring the custom_form in the auth example <https://github.com/locustio/locust/tree/master/examples/web_ui_auth/custom_form.py>`_.

Expand Down
3 changes: 3 additions & 0 deletions examples/web_ui_auth/custom_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def locust_init(environment, **_kwargs):
"name": "username",
# make field required
"is_required": True,
# override input type for HTML validation
# applies if !is_secret and !choices, and default_value is string | None
"type": "email",
},
# boolean checkmark field
{"label": "Admin", "name": "is_admin", "default_value": False},
Expand Down
1 change: 1 addition & 0 deletions locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
class InputField(TypedDict, total=False):
label: str
name: str
type: str | None
default_value: bool | None
choices: list[str] | None
is_secret: bool | None
Expand Down
3 changes: 2 additions & 1 deletion locust/webui/src/components/Form/CustomInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ICustomInput } from 'types/form.types';
export default function CustomInput({
name,
label,
type = 'text',
defaultValue,
choices,
isSecret,
Expand Down Expand Up @@ -54,7 +55,7 @@ export default function CustomInput({
name={name}
required={isRequired}
sx={{ width: '100%' }}
type='text'
type={type}
/>
);
}
1 change: 1 addition & 0 deletions locust/webui/src/types/form.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface ICustomInput {
label: string;
name: string;
type?: string;
choices?: string[] | null;
defaultValue?: string | number | boolean | null;
isSecret?: boolean;
Expand Down

0 comments on commit 813f0f2

Please sign in to comment.