Skip to content
Razor catalogue

On this page

@addTagHelper *, Webority.Ui.Razor

Rename a project

A short form, such as a rename or a note, opens in a dialog and posts back to the same page.

Rename and show an error
Show with an error
Show code
<div class="d-flex flex-wrap gap-2">
    <app-button type="Button" data-bs-toggle="modal" data-bs-target="#rename">Rename project</app-button>
    <app-button variant="Soft" href="?demo=errors">Show with an error</app-button>
</div>
<app-modal id="rename" title="Rename project">
    <app-modal-form id="rename-form" submit-label="Rename">
        <app-input id="name" label="Project name" name="name" value="Website refresh" />
    </app-modal-form>
</app-modal>

Destructive action

Use the danger tone on the submit button of an action that removes something, such as an archive. Add focus-cancel so the dialog opens on Cancel.

Archive a project
The archive dialog draws its submit button in the danger tone.
Show code
<app-button type="Button" tone="Danger" data-bs-toggle="modal" data-bs-target="#archive">Archive project</app-button>
<app-modal id="archive" title="Archive project" tone="Danger">
    <app-modal-form id="archive-form" submit-label="Archive" danger="true" focus-cancel="true">
        <p>The project leaves every list. You can restore it from the archive.</p>
    </app-modal-form>
</app-modal>

Fields, selects and rows

A longer form mixes single fields with two-column rows. Every field and row sits the same distance from the next.

Fields, selects and rows
Stacked fields, a select with helper text and two-column rows keep one distance between them.
Show code
<app-button type="Button" data-bs-toggle="modal" data-bs-target="#office">Edit office</app-button>
<app-modal id="office" title="Edit office">
    <app-modal-form id="office-form" submit-label="Save office">
        <app-input id="office-name" name="officeName" label="Office name" value="Head office" />
        <app-form-row columns="2">
            <app-input id="office-city" name="city" label="City" value="Gurugram" />
            <app-input id="office-region" name="region" label="State or region" value="Haryana" />
        </app-form-row>
        <app-select id="office-zone" name="timeZone" label="Time zone" helper-text="Used for attendance and shift times.">
            <app-option value="Asia/Kolkata" selected="true">India (IST)</app-option>
            <app-option value="Asia/Dubai">Gulf (GST)</app-option>
        </app-select>
        <app-form-row columns="2">
            <app-input id="office-address" name="address" label="Address" placeholder="Street address" />
            <app-input id="office-pincode" name="pincode" label="Pincode" placeholder="Postal or PIN code" />
        </app-form-row>
    </app-modal-form>
</app-modal>

Upload a file

A dialog that attaches a file posts it as multipart form data.

Upload a file
Set enctype to MultipartFormData and the form posts the file with the other fields.
Show code
<app-button type="Button" data-wui-open="#upload">Attach a document</app-button>
<app-modal id="upload" title="Attach a document">
    <app-modal-form id="upload-form" submit-label="Upload" enctype="AppModalFormEnctype.MultipartFormData">
        <app-input id="upload-title" name="title" label="Document title" />
        <app-file-picker id="upload-file" name="file" label="File" />
    </app-modal-form>
</app-modal>

Page hooks and a disabled submit

A page script finds its own hook on the form and enables the submit button once the person may post.

Page hook and a disabled submit
A data attribute on the tag lands on the form, so a page script finds it. The submit button starts disabled and the script enables it.
Show code
<app-button type="Button" data-wui-open="#swap">Swap device</app-button>
<app-modal id="swap" title="Swap device">
    <app-modal-form id="swap-form" data-page-hook="device-swap" submit-label="Swap" submit-disabled="true">
        <app-input id="swap-serial" name="serial" label="New serial number" />
    </app-modal-form>
</app-modal>

Every option

Every value of every prop, one cell each.

id

id (required): names the form that the footer buttons submit, no visible change

action

action not set (default): the form posts back to the current page, no visible change

method

method="post" (default): the form carries the antiforgery field
method="get": no antiforgery field, the fields post in the query string

enctype

enctype not set (default): the form posts urlencoded, no visible change
enctype="AppModalFormEnctype.MultipartFormData": the form posts its files

submit-label

submit-label not set (default): the submit button reads Save
submit-label="Rename": the submit button reads Rename

cancel-label

cancel-label not set (default): the cancel button reads Cancel
cancel-label="Keep editing": the cancel button reads Keep editing and still closes the dialog without posting

danger

danger="false" (default): the submit button uses the primary tone
danger="true": the submit button uses the danger tone, for a destructive action

focus-cancel

focus-cancel="false" (default): focus lands on the first field
focus-cancel="true": focus lands on the Cancel button

submit-disabled

submit-disabled="false" (default): the submit button is enabled
submit-disabled="true": the submit button is drawn disabled

hide-submit

hide-submit="false" (default): the footer holds Cancel and the submit button
hide-submit="true": the footer holds only Cancel

Reference

Try every prop, read the full list, and check keyboard and screen reader behaviour.

post get
(none) application/x-www-form-urlencoded multipart/form-data
Razor, the same props
<app-modal-form id="pg-form" submit-label="Rename">…</app-modal-form>

11 props.

Less common 11 props

PropTypeDefaultDescription
iddefault - string - The form's element id, which the footer buttons name. Required; a missing id throws.
actiondefault - string - Where the form posts. Unset posts back to the current page.
methoddefault post post | get post A get form carries no antiforgery field. Any other value throws.
enctypedefault - MultipartFormData | ApplicationXWwwFormUrlencoded - Writes the form's enctype. Set MultipartFormData for a form with a file input. Unset writes none. Needs the post method; a get form with an enctype throws.
submit-labeldefault Save string Save The submit button's label.
cancel-labeldefault Cancel string Cancel The cancel button's label. It closes the dialog without posting.
dangerdefault false bool false Draws the submit button in the danger tone, for a destructive action.
focus-canceldefault false bool false Puts initial focus on the Cancel button when the dialog opens, for a destructive action. Unset, focus lands on the first field.
submit-disableddefault false bool false Draws the submit button disabled, for a form the page script enables later. Not with hide-submit; both throw.
hide-submitdefault false bool false Leaves the submit button out of the footer, for a dialog the page script submits or that only shows. Not with submit-disabled; both throw.
data-*default - string - Any other attribute, such as a data hook, is written onto the form element.